2016-06-30 5 views
2

私は、rootで/ var/www/apps/example/current/publicにnginxで設定されたRailsアプリケーションを持っています。アクセスはhttps://www.example.comです。それはすべて素晴らしいです。私はブログを追加することにしました。私はWordpressに行きたいと思っていました。私は、サーバー、の/ var/www /のアプリケーション/ブログ上の別のディレクトリにインストールして、私は以下https://www.example.com/blogディレクトリ内のWordpress用のNginx設定

に行くことによってそれにアクセスできるようにしたい私のnginxの設定ファイルである:

server { 
    listen  443; 
    ssl on; 
    ssl_certificate /etc/ssl/certs/example.com.pem; 
    ssl_certificate_key /etc/ssl/certs/example.com.key; 

    server_name www.example.com; 
    root   /var/www/apps/example/current/public; 
    passenger_enabled on; 
    rails_env production; 

    client_max_body_size 100M; 
    client_body_buffer_size 256k; 

    error_page 404    /404.html; 

    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
    root html; 
    } 

    location /blog { 
    root /var/www/apps; 

    location ~ [^/]\.php(/|$) { 
     try_files $uri =404; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
    } 
} 

私はexample.com/blogに移動することができ、何の問題もなく私をそこに連れて行きます。問題は、きれいなURLを有効にして投稿を表示しようとしたときに発生します。それは/ブログのディレクトリを回避し、私のRailsアプリをヒット、私は/var/log/nginx/error.logで次のエラーが表示404で終わる:index index.phpディレクティブを追加

2016/06/30 17:24:32 [error] 7035#0: *20 "/var/www/apps/blog/hello-world/index.html" is not found (2: No such file or directory), client: 199.27.128.198, server: www.example.com, request: "GET /blog/hello-world/ HTTP/1.1", host: "www.example.com", referrer: "https://www.example.com/blog/" 

は修正されません。その問題は、/var/www/apps/blog/hello-world/index.phpが代わりに見つからないと述べているだけです。

アイデア?私は困惑している。

答えて

1

try_files $uri=404;は、パーマリンクには不十分です。

location /blog { 
    root /var/www/apps/blog; 

    try_files $uri $uri/ /index.php?$args; 

    location ~ \.php$ { 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include fastcgi_params; 
    } 
} 

または、non-root try_files redirectを試してみてください:かなりパーマリンクを有効にするには

、あなたはそれを変更する必要が

location /blog { 
    try_files $uri $uri/ /blog/index.php?$args; 

    location ~ \.php$ { 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include fastcgi_params; 
    } 
} 
+1

です解決策は正しい方向に私を指摘して以来。あなたが与えた最初の例で、 'try_files $ uri $ uri//blog/index.php?$ args;'を追加するだけです。 – Orlando

関連する問題