Setting up custom error pages are needed whenever the app goes in maintenance or when the code gets crashed
… In Nginx, its fairly simple but once when you know it.
Say your app example.com is residing in /var/www/apps/example
Nginx configurations
say your existing configuration looks like…
server{
listen 80;
server_name .example.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
proxy_pass http://127.0.0.1:9002;
}
}
add the error page configurations
server{
listen 80;
server_name .example.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
proxy_pass http://127.0.0.1:9002;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/www/maintenance/example;
}
}
Create the required html error page at /var/www/maintenance/example/500.html.
Now, restart the nginx to reload the configurations by issuing /etc/init.d/nginx restart.
And you are done!




Looks like one thing missing here,
proxy_intercept_errors on;
This is important for nginx to inspect response which is proxied….
PS: more here http://wiki.nginx.org/NginxHttpProxyModule#proxy_intercept_errors
[...] Check out the original for detail [...]
Nice. This was helpful!
Hi Abhishek,
That depends on your needs. In the case of my application, it handles 500 errors by itself. But when it isn’t running (in “maintenance mode”), nginx takes over and sends a proper 500 error page.
Regards.
I am having trouble getting my music to play this 404 page comes up saying not found. Please help me Thank you
[...] Here is a excellent tutorial show you how to Set up error pages in Nginx: Setting up custom error pages are needed whenever the app goes in maintenance or when the code gets crashed … In Nginx, its fairly simple but once when you know it. [...]
How can I turn off all the default error pages and use 1 custom made?
Thanks.