需要在nginx上提供自定义错误页面。当前配置如下所示:
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;
}
它适用于https://example.com/404之类的网址,但不适用于https://example.com/404/404如何使其工作?预先感谢。
我们将为文件创建一个位置块,我们可以在其中确保根目录与我们的文件系统位置匹配,并且只能通过内部Nginx重定向访问该文件:
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;
}