I'm trying to create a fallback for my error_page. Basically, the logic should be something like the following:
- load foobar.html
- does not exist on remote server -> load 404.html from remote server to show 404 page
- does not exist on remote server -> load 404.html on local filesystem
Loading both localhost/404.html
and localhost/global404.html
works, but when I break localhost/404.html
(by removing the file from the http server) it does not show the global404.html
page as I'd expect.
server {
listen 80;
server_name example.com www.example.com;
proxy_intercept_errors on;
location / {
proxy_pass http://localhost:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
error_page 404 /404.html;
}
location /404.html {
proxy_pass http://localhost:3000/404.html;
error_page 404 /global404.html;
}
location /global404.html {
root /usr/share/nginx/html;
}
}
The above works fine when I hit http://localhost/404.html
(when the 404.html file is on the remote server it shows that, when I delete the file it loads the global404.html file).
However, when I type a non-existent page I just get the default nginx 404 page.
Thanks to the wording of a comment left on the question, I managed to find the
recursive_error_pages
option which allows cascading/recursiveerror_pages
. I feel stupid for missing it in the documentation.But, simply doing
worked a charm. I love nginx.