Changing Passenger Default Error Page for Nginx
Asked Answered
P

2

7

Currently if there's a problem launching a Rails app on our server, users are taken to a Passenger error page with an error like "Ruby (Rack) application could not be started".

Is it possible to customize this error page and display something else so users of a live site don't see this?

I'm using nginx for the server.

Thanks

Plafond answered 1/12, 2011 at 18:58 Comment(2)
Can you post your Nginx config?Ducal
@DevinM - it's a generic rails app config.Plafond
M
6

In testing Passenger 5.1, I found that setting passenger_friendly_error_pages off is not enough to change the default error page. This disables exposing backtrace or environment variables but still shows Passenger's error page.

To resolve this I had to set the following:

passenger_intercept_errors on;
error_page 500 /500.html;

The command passenger_intercept_errors tells nginx to handle status codes of 400 or higher. The error_page command customizes the error. You might want to customize other errors as well.

For a Rails app, the location of the pages is relative to the public folder of the app (what you set in the root command for nginx).

As mentioned is this comment, the similar configuration for Apache is:

PassengerErrorOverride on
ErrorDocument 500 /path/to/500.html
Marketable answered 31/3, 2017 at 23:24 Comment(3)
I should note that since discovering this, I've change this back to passenger_intercept_errors off; because if our rails app returns a 404 error for a an API request with an expected JSON response, passenger was replacing the JSON response with the custom error page. I haven't yet found a way to make these both work.Marketable
Have you come across a working solution for the JSON response issue you encountered yet? I only want to intercept 503s and return a customized error page, but all other responses above 400 are interceptedCalceolaria
@Steven_JP I have not figured out how to get nginx to work with both JSON response and send custom error pages when it handles it's own. Perhaps turning off 404 custom error pages in nginx would work, but it also directly handles assets, so I want it to provide custom error pages for those (perhaps).Marketable
D
10

The users guide contains some good information on the various config options. There is an option to disable the friendly error pages which is what I think you may be seeing.

To disable the startup error message specify the following line in your config file:

passenger_friendly_error_pages off

You can place this inside the http block, server block or location block. If you place it in the http block it would disable it by default for all of the virtual hosts on that server. You can however override the setting in the server block by placing the same option inside a http block.

Ducal answered 1/12, 2011 at 19:18 Comment(2)
What is shown instead if I turn off 'friendly' error pages? Is that error info still logged to somewhere on my server? What about showing a custom error page instead (e.g. twitter's failwhale)?Kizzee
Bee, the error should show up in your nginx error.log. Then you just need a standard 500 page, which you can configure through nginx.Ran
M
6

In testing Passenger 5.1, I found that setting passenger_friendly_error_pages off is not enough to change the default error page. This disables exposing backtrace or environment variables but still shows Passenger's error page.

To resolve this I had to set the following:

passenger_intercept_errors on;
error_page 500 /500.html;

The command passenger_intercept_errors tells nginx to handle status codes of 400 or higher. The error_page command customizes the error. You might want to customize other errors as well.

For a Rails app, the location of the pages is relative to the public folder of the app (what you set in the root command for nginx).

As mentioned is this comment, the similar configuration for Apache is:

PassengerErrorOverride on
ErrorDocument 500 /path/to/500.html
Marketable answered 31/3, 2017 at 23:24 Comment(3)
I should note that since discovering this, I've change this back to passenger_intercept_errors off; because if our rails app returns a 404 error for a an API request with an expected JSON response, passenger was replacing the JSON response with the custom error page. I haven't yet found a way to make these both work.Marketable
Have you come across a working solution for the JSON response issue you encountered yet? I only want to intercept 503s and return a customized error page, but all other responses above 400 are interceptedCalceolaria
@Steven_JP I have not figured out how to get nginx to work with both JSON response and send custom error pages when it handles it's own. Perhaps turning off 404 custom error pages in nginx would work, but it also directly handles assets, so I want it to provide custom error pages for those (perhaps).Marketable

© 2022 - 2024 — McMap. All rights reserved.