Created
October 2, 2013 00:39
-
-
Save rtxanson/6787409 to your computer and use it in GitHub Desktop.
Nifty way of redirecting to error pages with nginx, using try_files and named locations.
This file contains hidden or 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
server { | |
error_page 404 = @notfound; | |
# You can also connect multiple errors to a location handler. | |
error_page 500 502 504 = @something_else; | |
# Try whatever paths, end with @notfound | |
location / { | |
try_files $uri $uri.html $uri.etc /index.html @notfound; | |
} | |
location @notfound { | |
try_files /404.html =404; # =404 is a shortcut to nginx's default error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment