Skip to content

Instantly share code, notes, and snippets.

@fboaventura
Forked from somebox/nginx.conf
Created July 18, 2018 20:26
Show Gist options
  • Save fboaventura/82d3eac907c4264a28ec7a42f7a7db4c to your computer and use it in GitHub Desktop.
Save fboaventura/82d3eac907c4264a28ec7a42f7a7db4c to your computer and use it in GitHub Desktop.
Nginx error page handling
# The following recipe works with upstream rails proxy for custom 404s and 500s.
# Errors are usually handled via rails except if proxy is really down, in which case
# nginx needs a bit more configration.
server {
# ...
location / {
error_page 404 = @rails; # let rails show a page with suggestions
try_files maintenance.html @rails;
}
location @rails {
proxy_pass ...
proxy_intercept_errors on; # Important!
}
error_page 500 502 503 @error_page;
# this handles 50x errors that happen via upstream proxy,
# when the normal error_page directive alone is not enough.
location @error_page {
root /var/nginx/app/htdocs; # location of 500.html file
internal;
rewrite ^ /500.html;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment