现象
最近Nginx出现下面的错误:
empty URI in redirect to named location "@400" while reading client request line。
配置如下:
error_page 400 405 @error_1;
location @error_1 {
default_type application/json;
return 400 '{"error": "error1"}';
}
原因
存在“特殊错误路径”,例如:
查了下资料,发现如果使用“特殊错误路径”访问返回405,将定向到虚拟路径@error_1,但是“特殊错误路径”的存在从而导致错误:
As for your other questions, the problem is that you are trying to redirect errors which appear during early request processing stages - when the request URI is not yet parsed - to a named location. Named locations are designed to preserve existing request URI, and redirecting such an incomp