【发布时间】:2016-11-03 04:07:54
【问题描述】:
我有一个使用 nginx 配置的 Rails 应用程序,其根目录位于 /var/www/apps/example/current/public。访问地址为https://www.example.com。这一切都很好。我决定添加一个博客,我想使用 Wordpress。我将它安装在服务器上的另一个目录 /var/www/apps/blog 中,我希望能够通过转到 https://www.example.com/blog 来访问它
下面是我的 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 并尝试查看帖子时,问题就出现了。它绕过 /blog 目录并访问了我的 Rails 应用程序,以 404 结束。我在 /var/log/nginx/error.log 中看到以下错误:
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/"
添加index index.php 指令并不能解决问题,它只是说明没有找到/var/www/apps/blog/hello-world/index.php。
有什么想法吗?我被难住了。
【问题讨论】:
标签: ruby-on-rails wordpress nginx