Skip to content

Instantly share code, notes, and snippets.

@duebbert
Created Nov 16, 2015
Embed
What would you like to do?
NGINX config to first check a server, e.g. webpack-dev-server, if it's down then local files.
server {
[... normal configs]
# Try webpack server first, if error 502 then go try files
location ~ ^/.+/static/js/.+\.js$ {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Forwarded-Host 127.0.0.1:8080;
error_page 502 = @localjs;
}
# Trying js locally after webpack failed
location @localjs {
try_files $uri =404;
}
[... other locations]
}
@duebbert

This comment has been minimized.

Copy link
Owner Author

@duebbert duebbert commented Nov 16, 2015

Couldn't find something like this anywhere. The "try_files" directive works the other way round, i.e. first try local files then fallback (named location or internal).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment