【问题标题】:nginx is not showing custom error page with uwsginginx 没有显示带有 uwsgi 的自定义错误页面
【发布时间】: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


【解决方案1】:

不确定它是否记录在某处,但我认为 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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-08
    相关资源
    最近更新 更多