Skip to content

Instantly share code, notes, and snippets.

@somebox
Created March 13, 2012 16:19
Show Gist options
  • Save somebox/2029709 to your computer and use it in GitHub Desktop.
Save somebox/2029709 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;
}
}
@somebox
Copy link
Author

somebox commented Mar 28, 2012

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