nginx – use local error_page when remote error_page not found

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.

I have the following, and 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;
    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;