Skip to content

Instantly share code, notes, and snippets.

Created Nov 16, 2015
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_set_header X-Forwarded-Host;
error_page 502 = @localjs;
# Trying js locally after webpack failed
location @localjs {
try_files $uri =404;
[... other locations]

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