One location block for all Nginx error codes
error-handling, http-status-code-404, nginx
Solution
error_page 403 /error/403.html;
error_page 404 /error/404.html;
error_page 405 /error/405.html;
error_page 500 501 502 503 504 /error/5xx.html;
location ^~ /error/ {
internal;
root /var/www/default;
}
- http://nginx.org/r/location
- http://nginx.org/r/error_page
- http://nginx.org/r/root
Problem
Is it possible to have the 40x and 50x errors served by a single location rule? Something like: ``` error_page 403 /403.html; error_page 404 /404.html; error_page 405 /405.html; error_page 500 501 502 503 504 /5xx.html; location ~ /(?:40[345]|5xx)[.]html$ { root /var/www/default/error; } ```