Reputation: 21
Need to provide custom error pages on nginx. Currently config looks like below:
error_page 404 /404.html;
error_page 500 /500.html;
error_page 502 /502.html;
location ~ ^/(404.html|500.html|502.html){
root /etc/nginx/error-pages;
}
It works for urls like https://example.com/404, but it doesn't for https://example.com/404/404 How to make it work ? Thanks in advance.
Upvotes: 0
Views: 183
Reputation: 5276
We will create a location block for the file, where we are able to ensure that the root matches our file system location and that the file is only accessible through internal Nginx redirects:
error_page 404 /custom_404.html;
location = /custom_404.html {
root /etc/nginx/error-pages;
internal;
}
error_page 500 502 503 504 /custom_50x.html;
location = /custom_50x.html {
root /etc/nginx/error-pages;
internal;
}
Upvotes: 1