Nginx reverse proxy error page
I'm using nginx as reverse proxy for a single machine. I would like to have an error page when the backend machine goes down.
This is my configuration file:
server {
listen 80;
access_log /var/log/nginx/access.log;
root /var/www/nginx;
error_page 403 404 500 502 503 504 /error.html;
location / {
proxy_pass http://192.168.1.78/;
include /etc/nginx/proxy.conf;
}
Aha, I see the problem. You have provided no way for nginx to actually serve static files such as /error.html
, so it is trying to pass them upstream to your backend.
The quick fix would be:
location /error.html {
internal;
}
This will cause nginx to handle /error.html
itself. It will then try to serve the file out of the defined document root
.
By the way, you probably want to use different error pages for 4xx errors and 5xx errors. "Not found" or whatever is not what you want people (or search engines!) to see if a backend is down temporarily.