5

我有一个在 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 应用程序自定义错误页面需要什么?

4

3 回答 3

1

请尝试以下方法:

# 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 状态响应(我不知道那时会发生什么)。

相关链接

于 2013-06-17T07:01:49.483 回答
1

你可能passenger_intercept_errors on;在你的 nginx 配置中丢失了

有关更多信息,请参阅此指令的乘客文档

于 2013-09-13T08:38:42.430 回答
0

我使用的配置:

error_page   500 502 503 504  /50x.html;

location = /50x.html {
   root   html;
}
于 2013-06-14T03:00:17.003 回答