Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails app on nginx+passenger not showing custom error pages

I have a Rails app running on nginx 1.2.0 and passenger 3.0.7. I would like to have the custom error pages in the rails app (e.g. /rail_app/public/500.html) be displayed when the appropriate http error occurs within the app.

Here is my current nginx config file:

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

This configuration does not show the rails app customer error page rather just sends the http error status code to the client.

Anyone know what it takes to have nginx/passenger send the rails app custom error page to the client with the http error status code?

like image 278
Rafael Avatar asked Nov 02 '22 21:11

Rafael


2 Answers

Please try the following:

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

Reconfiguring the root directive makes no sense, as it is already set to the path you specified before. The alias ensures that the specific location is internally matched to a different location on the file system. All incoming request parameters should be passed along and if your Rails app is taking care of things at this point it should answer. Just make sure that your Rails app isn't answering with a 500 status again (I don’t know what would happen then).

Related Links

  • alias
like image 108
Fleshgrinder Avatar answered Nov 09 '22 16:11

Fleshgrinder


You're probably missing passenger_intercept_errors on; in your nginx config

see the passenger docs for this directive for more info

like image 27
gingerlime Avatar answered Nov 09 '22 14:11

gingerlime