![nginx 的自定义 502 坏网关,无法使其工作,出了什么问题?](https://linux22.com/image/595787/nginx%20%E7%9A%84%E8%87%AA%E5%AE%9A%E4%B9%89%20502%20%E5%9D%8F%E7%BD%91%E5%85%B3%EF%BC%8C%E6%97%A0%E6%B3%95%E4%BD%BF%E5%85%B6%E5%B7%A5%E4%BD%9C%EF%BC%8C%E5%87%BA%E4%BA%86%E4%BB%80%E4%B9%88%E9%97%AE%E9%A2%98%EF%BC%9F.png)
我正在尝试使用 unicorn 捕获 nginx 的 502 bad gataway。当 unicorn 处于不是正在运行。我尝试在 Unicorn 未运行时使用自定义错误页面,但无济于事。
我错过了什么?根据文档,这应该是正确的,但我只是没有看到任何错误。
上游独角兽 { 服务器 unix:/srv/host/shared/tmp/unicorn.sock fail_timeout=0; }
server {
listen 80 deferred;
server_name host.com host.com
client_max_body_size 4G;
keepalive_timeout 10;
root /srv/host/public;
location / {
try_files /system/maintenance.html $uri/index.html $uri @unicorn;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
error_page 502 /system/maintenance.html;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
}
我的 nginx error.log 显示:
unix:/srv/host/shared/tmp/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 83.117.60.95, server: host.com, request: "GET / HTTP/1.1", upstream: "http://unix:/srv/host/shared/tmp/unicorn.sock:/", host: "host.com"
答案1
是的,你可以在 nginx 中自定义错误页面。在你的配置中添加类似以下内容:
error_page 502 /path/to/error-pages/502_bad_gateway.html;