Nginx 默认错误页面仍然显示
Nginx default error page is still showing
我通过这些行向 Nginx 添加了自定义错误页面:
error_page 400 /custom.html;
location = /custom.html {
root /somewhere/html;
internal;
}
location /test {
return 400;
}
它 returns 我的测试位置自定义错误页面;问题是对于某些请求,例如当请求 header 太大时,它仍然 returns Nginx 的默认错误页面。
<html>
<head><title>400 Request Header Or Cookie Too Large</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>Request Header Or Cookie Too Large</center>
<hr><center>nginx</center>
</body>
</html>
显然这个特定错误在内部使用 code 494。
你可以试试
error_page 494 =400 /custom.html
我在 nginx 邮件列表上发现:
Try handling 494 errors instead. It's a custom code used to
report "Request Header Too Large" errors, translated to 400 just
before returning to client. It was introduced in nginx 0.9.4 to
make it possible to define a custom error page for these
particular errors separately from generic 400 errors.
https://mailman.nginx.org/pipermail/nginx/2018-June/056342.html
我通过这些行向 Nginx 添加了自定义错误页面:
error_page 400 /custom.html;
location = /custom.html {
root /somewhere/html;
internal;
}
location /test {
return 400;
}
它 returns 我的测试位置自定义错误页面;问题是对于某些请求,例如当请求 header 太大时,它仍然 returns Nginx 的默认错误页面。
<html>
<head><title>400 Request Header Or Cookie Too Large</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>Request Header Or Cookie Too Large</center>
<hr><center>nginx</center>
</body>
</html>
显然这个特定错误在内部使用 code 494。
你可以试试
error_page 494 =400 /custom.html
我在 nginx 邮件列表上发现:
Try handling 494 errors instead. It's a custom code used to report "Request Header Too Large" errors, translated to 400 just before returning to client. It was introduced in nginx 0.9.4 to make it possible to define a custom error page for these particular errors separately from generic 400 errors.
https://mailman.nginx.org/pipermail/nginx/2018-June/056342.html