10

Following is a sample Nginx server configuration. Without the "magical talisman" location block, proxied error content results in an Nginx 404 page rather than the customized error page being served.

Removing the proxy_intercept_errors directive serves a proper proxied error page with proper http error code headers.

Nonproxied error pages are rendered properly regardless of the presence of the magical talisman.

Any ideas as to what exactly is going on?

server {
    server_name     mydomain.com "";
    listen          80;
    root            /var/www;
    error_page      400 401 402 403 404 500 501 502 503 504 /admin/error_page.htm;
    proxy_intercept_errors on;

    location /proxy/ {
        proxy_read_timeout  60s;
        proxy_set_header    Host $host;
        proxy_pass          http://myservers;
    }

    location /test404/ {
        return 404;
    }

    location /admin/ {    # this line constitute a magical talisman that fixes proxied error interception(???)(!)
        rewrite ^(/admin)(.*)$ /admin$2 break;
    }
}
Aubrey Falconer
  • 303
  • 1
  • 2
  • 6

1 Answers1

6

I am sorry this answer kicks in late, bu as of now, with the current v1.8.1 stable version, the configuration you provided should work without any talisman.

If you provided the version which you were experimenting on, it would be an idea to see if a bug has been corrected or if the configuration was flawed.

I suggest you double check your configuration, since you definitely do not need this /admin/ location nor its contained rewrite directive. Take a very special care at removing everything which is not part of this test (and that you do not show) as it might interfere.

As a last resort, you could try this following, successfully tested, configuration snippet, and slowly integrate changes and see at which point results diverge from expectations:

server {
    listen      80;
    listen      [::]:80;
    server_name example.org;

    location /proxy {
        return 418 "Host: $host, Connection: $http_connection";
    }
}

server {
    listen      80;
    listen      [::]:80;
    server_name example.com;

    root /var/ious/files;

    error_page 418 = /error_page.html;
    proxy_intercept_errors on;

    location /proxy {
        proxy_pass http://example.org;
    }
}
Bernard Rosset
  • 1,323
  • 12
  • 24
  • Thanks, Bernard. I'm marking your answer as accepted since enough time has passed that I no longer recall what Nginx version I was testing against when the original question was posed. – Aubrey Falconer Aug 03 '17 at 21:43