【问题标题】:Rails App behind Wordpress using fastcgi_intercept_errors使用 fastcgi_intercept_errors 在 Wordpress 后面的 Rails 应用程序
【发布时间】:2016-07-30 23:47:00
【问题描述】:

我正在开始将 WordPress 网站迁移到 Rails 应用程序。迁移需要在接下来的几个月中逐步完成,因此我需要能够并行运行两个站点。在测试环境中使用 fastcgi_intercept_errors 我已经设法让 WordPress 返回的任何 404 错误使用以下配置转发到 Rails 应用程序:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        server_name mydomain.com;
        root         /var/www/html/wordpress;
    index index.php index.html

        error_page   500 502 503 504 404 @rails;

    location / {
        try_files $uri $uri/ /index.php?$args;
        recursive_error_pages on;
        error_page 404 = @rails;
    }

    location ~ \.php$ {
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
                include fastcgi_params;
        error_page 404 = @rails;

        }

    location @rails{
        passenger_enabled on;
        passenger_user user;
        rails_env development;
        root /home/user/rails_app/app/public;
    }
}

当 rails 应用程序引用任何 /assets 链接时,问题就出现了,它们总是转发回 rails 应用程序并始终加载应用程序的根位置。

有没有办法解决这个问题,以便资产也被视为 rails 应用程序的一部分?

【问题讨论】:

    标签: ruby-on-rails ruby wordpress nginx passenger


    【解决方案1】:

    这个 nginx 配置能够满足我的需要。错误页面指令被移动到唯一的 php 位置,并添加了一个资产位置以将默认根位置从 php 应用程序重定向到 ruby​​ 应用程序公共文件夹。

    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
    
        server_name mydomain.com;
        root         /var/www/html/wordpress;
        index index.php index.html;
    
        location / {
            try_files $uri $uri/ /index.php?$args;
            recursive_error_pages on;
            error_page 404 = @rails;
        }
    
        location ~ \.php$ {
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_intercept_errors on;
            include fastcgi_params;
            error_page 404 = @rails;
        }
    
        location ^~ /assets/ {
            root /home/user/rails_app/app/public;
        }
    
        location @rails{
            passenger_enabled on;
            passenger_user user;
            rails_env production;
            root /home/user/rails_app/app/public;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-02-14
      • 1970-01-01
      • 1970-01-01
      • 2020-05-19
      • 2013-12-03
      • 2019-01-27
      • 1970-01-01
      • 2013-07-06
      • 2013-10-04
      相关资源
      最近更新 更多