nginx反向代理请求失败时,总是返回默认的502/504页面,在server字段下配置error_page属性仍然不生效。

在查阅资料后发现,似乎是因为nginx在location中找不到自定义的502、504错误页导致的。解决方法也很简单,手动指定错误页面的文件根目录即可。具体可参考下文示例配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server {
listen 80;
server_name example.com;

error_page 502 /502.html;
error_page 504 /504.html;

location / {
proxy_pass http://p.example.com;
}

location = /502.html {
root /usr/share/nginx/html;
internal;
}

location = /504.html {
root /usr/share/nginx/html;
internal;
}
}

广告
广告正在加载中...
暂不开放评论,如对本文有任何疑问,请联系i#mr-wu.top(#替换为@)