Serve custom error pages from reverse proxy

From Wiki
Revision as of 16:35, 3 December 2018 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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;

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;