nginx没有显示uwsgi的自定义错误页面

时间:2018-10-27 17:11:45

标签: nginx webserver uwsgi wsgi

我正在尝试为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指令对其进行了测试,并且它是相同的。

1 个答案:

答案 0 :(得分:0)

不确定是否在某处记录了文档,但我认为error_page不能链接到另一个error_page

在您的情况下,error_page 404try_files语句的行为非常相似。有关详细信息,请参见this document

因此,可以替换链接的error_page,如下所示:

location @icons {
    root /home/dmoj/site/resources/icons;
    try_files $uri @uwsgi;
    log_not_found off;
}