【发布时间】:2020-06-12 07:20:53
【问题描述】:
环境如下:
我有https://website.com 和一个博客https://website.com/blog
根路径指向一个由Passenger托管的Rails应用,博客子目录通过php-fpm指向一个WordPress应用
我的 Nginx 配置一切正常,但是当我尝试将永久链接结构更改为“普通”以外的任何内容时,我从 Rails 应用程序中得到一个 404 页面,就好像没有使用位置块一样。我尝试在调试模式下查看错误日志,我确实看到它尝试 try_files,但最终它失败并出现 Rails 404 页面。
值得注意的是,整个网站都在 Cloudflare 之后。不确定它是否可能与此有关,尽管我有点怀疑。
这是我正在使用的几乎可以工作的 Nginx 配置:
server {
listen 80 default_server;
server_name IP_ADDRESS;
passenger_enabled on;
passenger_app_env production;
passenger_ruby /home/ubuntu/.rbenv/shims/ruby;
root /web/rails/public;
client_max_body_size 20M;
location ^~ /blog {
passenger_enabled off;
alias /web/blog;
index index.php index.htm index.html;
# Tried the commented line below, but then nothing works.
# try_files $uri $uri/ /blog/index.php?$args;
# The line below works, but peramlinks don't.
try_files $uri $uri/ /blog/index.php?q=$uri&$args;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
# Tried the commented line below, but then nothing works
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# The line below works, but peramlinks don't.
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
}
【问题讨论】:
标签: wordpress nginx permalinks nginx-config