Nginx: Serve error pages from reverse proxy, not from upstream server

Written by - 0 comments

Published on September 21st 2017 - Listed in Internet Linux Nginx


If you run Nginx as a reverse proxy and you want to serve error pages from the reverse proxy itself, don't forget to set the following proxy setting:

proxy_intercept_errors on;

Without this, Nginx will forward the error page coming from the upstream server to the client.

If you want certain error pages still being delivered from the upstream server (for example 404), then simply don't specify the error_page 404 on the reverse proxy:

  error_page 400 /400.html;
  location /400.html {
    root   /var/www/errorpages;
    internal;
  }

  error_page 500 /500.html;
  location /500.html {
    root   /var/www/errorpages;
    internal;
  }

  error_page 502 /502.html;
  location /502.html {
    root   /var/www/errorpages;
    internal;
  }

  error_page 503 /503.html;
  location /503.html {
    root   /var/www/errorpages;
    internal;
  }

  error_page 504 /504.html;
  location /504.html {
    root   /var/www/errorpages;
    internal;
  }


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.