Skip to content

Instantly share code, notes, and snippets.

@rtxanson
Created October 2, 2013 00:39
Show Gist options
  • Save rtxanson/6787409 to your computer and use it in GitHub Desktop.
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.
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