Serve custom error pages from reverse proxy

From Wiki
Jump to: navigation, search

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

If you want nginx to process errors directly you will need to add the following directive to the proxy config.

proxy_intercept_errors on;

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

To customize the error pages returned location directives can be added. For example.

  error_page 404 /custom_404.html;

  location = /custom_404.html {
    root   /usr/share/nginx/html;
    internal;
  }

This can be done for any error code. For example, a custom 500 error page is specified as follows.

  error_page 500 /500.html;

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