Custom Bad Gateway Page with Nginx
It's similar to setting up the custom 404 pages. Here's what I've got.
#site-wide error pages
error_page 404 /404.html;
error_page 500 502 503 504 /500.html;
using debian (9.3 stretch actually) i did following steps:
create
/var/www/html/502.html
with the content for the 502 error pageedit
/etc/nginx/sites-enabled/mywebsite.conf
so it looks similar like this:
server {
listen 80; listen [::]:80;
server_name www.mywebsite.com;
error_page 502 /502.html;
location /502.html {
root /var/www/html;
}
}
- then restarted nginx using
service nginx restart
There are three pieces that must be in place in order for your custom error page to display instead of the generic "Bad Gateway" error.
You must create an html file named something like "500.html" and place it in the root. In the case of Rails running behind Nginx, this means putting it at public/500.html.
You must have a line in your config file that points at least the 502 errors to that 500.html page like this:
error_page 502 /500.html;
You must have a location block for /500.html in your config file. If your root is already defined, this block can be empty. But the block must exist nonetheless.
location /500.html{ }