Created
March 13, 2012 16:19
-
-
Save somebox/2029709 to your computer and use it in GitHub Desktop.
Nginx error page handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
http://wiki.nginx.org/HttpProxyModule#proxy_intercept_errors