ruby-on-rails - nginx+passenger 上的 rails 应用程序未显示自定义错误页面

标签 ruby-on-rails nginx passenger

我有一个在 nginx 1.2.0 和乘客 3.0.7 上运行的 Rails 应用程序。我希望在应用程序中发生适当的 http 错误时显示 Rails 应用程序中的自定义错误页面(例如/rail_app/public/500.html)。

这是我当前的 nginx 配置文件:

http {
    passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7;
    passenger_ruby /usr/bin/ruby;

    include       mime.types;
    default_type  application/octet-stream;

    #access_log  /opt/nginx/logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    server {
        listen 80;
        server_name localhost;
        root /var/www/dashboard/current/public;
        passenger_enabled on;
        passenger_min_instances 1;
#       listen 443;
#       ssl on;
#       ssl_certificate /opt/nginx/conf/server.crt;
#       ssl_certificate_key /opt/nginx/conf/server.key;
        error_page 500 502 503 504 /500.html;
        location = /500.html {
            root /var/www/dashboard/current/public/;
        }
    }
}

此配置不显示 rails 应用程序客户错误页面,而只是将 http 错误状态代码发送到客户端。

任何人都知道让 nginx/passenger 将带有 http 错误状态代码的 rails 应用程序自定义错误页面发送到客户端需要什么?

最佳答案

请尝试以下操作:

# We use the x just because it is for all 5xx errors.
error_page 500 502 503 504 /5xx.html;
location = /5xx.html {
    alias /var/www/dashboard/current/public/;
}

重新配置 root指令没有意义,因为它已经设置为您之前指定的路径。 alias确保特定位置在内部匹配到文件系统上的不同位置。所有传入的请求参数都应该被传递,如果你的 Rails 应用程序在此时处理事情,它应该回答。只需确保您的 Rails 应用程序不再以 500 状态响应(我不知道会发生什么)。

相关链接
  • alias
  • 关于ruby-on-rails - nginx+passenger 上的 rails 应用程序未显示自定义错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16609947/

    相关文章:

    ruby-on-rails - Nginx 和 Passenger 用户权限。最佳实践?

    javascript - 将 JavaScript 选择变量传递给 Rails Controller

    ruby-on-rails - 在 rails 应用程序中使用 LibreOffice 将 Doc 的前几页导出为 PDF

    ruby-on-rails - 无法让 PostGIS 与 Heroku/Rails 一起使用 - NoMethodError : undefined method `geography' / 'st_point'

    ssl - 为间歇性服务配置 proxy_pass

    php - 413 请求实体太大 - Nginx 1.8.1

    django - dreamhost python3 Django乘客设置导入Cookie

    ruby-on-rails - 为什么没有填充我的关联对象 ID?

    nginx - "How to fix ' 错误 : must either provide a name or specify --generate-name ' in Helm"

    django - 在 Dreamhost 和 Passenger WSGI 上为 Django 设置环境变量