Debian

Nginx 返回 502 Bad Gateway

  • June 13, 2013

我正在嘗試按照本指南設置 Nginx 網路伺服器,但使用perusio 的配置。當我嘗試訪問該站點時,我得到一個 502 Bad Gateway 頁面。

搜尋錯誤我看到一些人報告說設置 fastcgi 緩衝區大小已經解決了他們的問題。但是,這對我不起作用。儘管我的錯誤日誌中的消息與所述的不同:

2013/06/11 10:21:24 [info] 32684#0: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:181
2013/06/11 10:21:24 [alert] 32692#0: epoll_ctl(1, 0) failed (1: Operation not permitted)
2013/06/11 10:21:24 [alert] 32692#0: failed to register channel handler while initializing push module worker (1: Operation not permitted)
2013/06/11 10:21:24 [alert] 32691#0: epoll_ctl(1, 0) failed (1: Operation not permitted)
2013/06/11 10:21:24 [alert] 32691#0: failed to register channel handler while initializing push module worker (1: Operation not permitted)
2013/06/11 10:21:25 [alert] 32686#0: cache manager process 32691 exited with fatal code 2 and cannot be respawned

搜尋此錯誤,似乎nginx沒有與php5-fpm. 我已經驗證它php5-fpm正在執行:

$ ps auxw | grep php
root       853  0.0  0.8 290416  4504 ?        Ss   10:21   0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data   854  0.0  0.6 290416  3488 ?        S    10:21   0:00 php-fpm: pool www      
www-data   855  0.0  0.6 290416  3488 ?        S    10:21   0:00 php-fpm: pool www      
kyle       973  0.0  0.2   3824  1072 pts/0    S+   10:42   0:00 grep php

並聆聽:

$ netstat --unix -l
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     43115    /var/run/mysqld/mysqld.sock
unix  2      [ ACC ]     SEQPACKET  LISTENING     2674     /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     4772     /var/run/fail2ban/fail2ban.sock
unix  2      [ ACC ]     STREAM     LISTENING     43450    /var/run/php5-fpm.sock
unix  2      [ ACC ]     STREAM     LISTENING     4792     @/tmp/fam-root-

我的nginx.conf包括upstream_phpcgi_unix.conf所以它應該嘗試php5-fpm通過 Unix 套接字連接:

## Add as many servers as needed. Cf. http://wiki.nginx.org/HttpUpstreamModule.
upstream phpcgi {
   ## If your version of Nginx doesn't have the fair load balancer:
   ## https://github.com/gnosek/nginx-upstream-fair comment out the
   ## following line.
   fair;
   server unix:/var/run/php-fpm.sock;
   server unix:/var/run/php-fpm-zwei.sock;
   ## Create a backend connection cache. Note that this requires
   ## Nginx version greater or equal to 1.1.4.
   ## Cf. http://nginx.org/en/CHANGES. Comment out the following
   ## line if that's not the case.
   keepalive 5;
}

## Add a third pool as a fallback.
upstream phpcgi_backup {
   server unix:/var/run/php-fpm-bkp.sock;
   ## Create a backend connection cache. Note that this requires
   ## Nginx version greater or equal to 1.1.4.
   ## Cf. http://nginx.org/en/CHANGES. Comment out the
   ## following line if that's not the case.
   keepalive 1;
}

我還應該看什麼?

我能夠通過使用aptitude purge刪除所有 PHP 包及其配置文件以及nginx. 然後,我根據需要單獨重新安裝了每個 PHP 包。我還使用了 perusio 的 PHP-FPM配置文件。

引用自:https://unix.stackexchange.com/questions/79026