nginx +乘客的rails应用程序没有显示自定义错误页面

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

这是我目前的nginxconfiguration文件:

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/; } } } 

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

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

请尝试以下操作:

 # 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

您可能错过了passenger_intercept_errors on; 在你的nginx配置中

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

我使用的配置:

 error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }