Why does Nginx's proxy_intercept_errors directive require a rewrite to work properly?

Solution 1:

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;
    }
}