Skip to content

Instantly share code, notes, and snippets.

@duebbert
Created November 16, 2015 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duebbert/c1ab167a16e6cab6dd45 to your computer and use it in GitHub Desktop.
Save duebbert/c1ab167a16e6cab6dd45 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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