以下是 Nginx 服务器配置示例。如果没有“魔法护身符”位置块,代理的错误内容会导致 Nginx 404 页面,而不是提供自定义的错误页面。
删除 proxy_intercept_errors 指令会提供带有正确 http 错误代码标头的正确代理错误页面。
无论魔法护身符是否存在,非代理错误页面都会正确呈现。
关于究竟发生了什么的任何想法?
server {
server_name mydomain.com "";
listen 80;
root /var/www;
error_page 400 401 402 403 404 500 501 502 503 504 /admin/error_page.htm;
proxy_intercept_errors on;
location /proxy/ {
proxy_read_timeout 60s;
proxy_set_header Host $host;
proxy_pass http://myservers;
}
location /test404/ {
return 404;
}
location /admin/ { # this line constitute a magical talisman that fixes proxied error interception(???)(!)
rewrite ^(/admin)(.*)$ /admin$2 break;
}
}
Run Code Online (Sandbox Code Playgroud)