nginx 没有显示带有 uwsgi 的自定义错误页面
nginx is not showing custom error page with uwsgi
我正在尝试为 502 和 504 答案添加自定义错误页面。目前我的站点有以下 nginx 配置(其他配置文件未受影响):
server {
listen 80;
listen [::]:80;
server_name 10.12.112.163;
add_header X-UA-Compatible "IE=Edge,chrome=1";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
charset utf-8;
try_files $uri @icons;
error_page 502 504 /502.html;
location = /502.html {
root /home/dmoj/site;
internal;
}
location @icons {
root /home/dmoj/site/resources/icons;
error_page 403 404 = @uwsgi;
log_not_found off;
}
location @uwsgi {
uwsgi_read_timeout 600;
uwsgi_pass unix:///tmp/dmoj-site.sock;
include uwsgi_params;
}
}
当我停止 uwsgi 并将浏览器转到 10.12.112.163 时,会显示 nginx 的默认“502 Bad Gateway”消息,但是当我转到 10.12.112.163/502.html 时,我的页面显示完美。
我在没有internal
指令的情况下也进行了测试,结果是一样的。
不确定它是否在某处记录,但我认为 error_page
不能链接到另一个 error_page
。
在您的例子中,error_page 404
与 try_files
语句的行为非常相似。有关详细信息,请参阅 this document。
所以你的链接 error_page
可以被替换,像这样:
location @icons {
root /home/dmoj/site/resources/icons;
try_files $uri @uwsgi;
log_not_found off;
}
我正在尝试为 502 和 504 答案添加自定义错误页面。目前我的站点有以下 nginx 配置(其他配置文件未受影响):
server {
listen 80;
listen [::]:80;
server_name 10.12.112.163;
add_header X-UA-Compatible "IE=Edge,chrome=1";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
charset utf-8;
try_files $uri @icons;
error_page 502 504 /502.html;
location = /502.html {
root /home/dmoj/site;
internal;
}
location @icons {
root /home/dmoj/site/resources/icons;
error_page 403 404 = @uwsgi;
log_not_found off;
}
location @uwsgi {
uwsgi_read_timeout 600;
uwsgi_pass unix:///tmp/dmoj-site.sock;
include uwsgi_params;
}
}
当我停止 uwsgi 并将浏览器转到 10.12.112.163 时,会显示 nginx 的默认“502 Bad Gateway”消息,但是当我转到 10.12.112.163/502.html 时,我的页面显示完美。
我在没有internal
指令的情况下也进行了测试,结果是一样的。
不确定它是否在某处记录,但我认为 error_page
不能链接到另一个 error_page
。
在您的例子中,error_page 404
与 try_files
语句的行为非常相似。有关详细信息,请参阅 this document。
所以你的链接 error_page
可以被替换,像这样:
location @icons {
root /home/dmoj/site/resources/icons;
try_files $uri @uwsgi;
log_not_found off;
}