Nginx

為 nginx 定制 502 錯誤網關,無法正常工作,這是怎麼回事?

  • September 13, 2012

我試圖用 unicorn 為 nginx 捕捉 502 錯誤密碼。獨角獸執行時會引發此錯誤。當獨角獸沒有執行無濟於事時,我嘗試使用自定義錯誤頁面。

我錯過了什麼?根據文件,這應該是正確的,我只是沒有看到任何錯誤。

上游獨角獸 { 伺服器 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"

是的,您可以在 nginx 中擁有自定義錯誤頁面。將類似以下內容添加到您的配置中:

error_page  502 /path/to/error-pages/502_bad_gateway.html;

引用自:https://serverfault.com/questions/427180