【问题标题】:NGINX + Passenger w/ Rails + WordPress permalinksNGINX + 乘客 w/ Rails + WordPress 永久链接
【发布时间】: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


    【解决方案1】:

    我想简短地发表评论,但我没有足够的声誉。

    • 我使用了以下块并为我工作。我添加了一个 add_header 指令只是为了调试我的请求是否到达了正确的块。
    location ^~ /blog {
        try_files $uri $uri/ /index.php?$args;
        add_header reached blog;
            location ~ \.php$ {
                include fastcgi_params;
                fastcgi_pass php;
            }
    }
    
    • 如果您的服务器位于 CloudFlare 之后,如果您使用的是 Ubuntu/Mac,则可以尝试在本地计算机上输入 /etc/hosts。这将停止 DNS 查找,并且将直接从 IP 地址访问站点。

    • 检查是否由于任何其他 Nginx 配置而发生任何重定向。

    • 另外,您在问题中提到站点是https://,而您的服务器块只有listen 80,表示非HTTPS。

    • 使用

      检查响应标头
      curl -XGET -IL site-name.tld
      

      这可能会帮助您更多地调试情况。

    • aliasroot 指令 https://stackoverflow.com/a/10647080/12257950 之间的区别

    【讨论】:

      猜你喜欢
      • 2016-12-06
      • 2013-03-26
      • 2015-02-20
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      • 2017-10-05
      相关资源
      最近更新 更多