【发布时间】:2019-04-01 03:19:16
【问题描述】:
我正在尝试为 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 指令的情况下对其进行了测试,结果是一样的。
【问题讨论】:
-
尝试用
try_files $uri @uwsgi;替换error_page 403 404 = @uwsgi; -
感谢@RichardSmith!你成功了!
标签: nginx webserver uwsgi wsgi