.png)
6 時間のデバッグの後、これをあきらめます :|
LAN には nginx+php-fpm+mysql があり、約 100 個の wordpress があります (さまざまなデザイナー/開発者が作成し、テスト wordpress セットアップに取り組んでいる)。
私たちは長い間、問題なく nginx を使用しています。
今日、突然、nginx が「504 Gateway Time-out」を返し始めました...
仮想ホストの nginx エラー ログを確認しました...
2010/09/06 21:24:24 [error] 12909#0: *349 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 21:25:11 [error] 12909#0: *349 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 21:25:11 [error] 12909#0: *443 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 21:25:12 [error] 12909#0: *443 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:08:32 [error] 12909#0: *1025 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:09:33 [error] 12909#0: *1025 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:09:40 [error] 12909#0: *1064 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:09:40 [error] 12909#0: *1064 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:24:44 [error] 12909#0: *1313 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:24:53 [error] 12909#0: *1313 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
TCP モードでポート 9000 で php-fpm を実行しているときに、「netstat | grep 9000」を実行したところ、異常なことに気付きました... (読みやすくするために、出力の一部をここに貼り付けます)
tcp 9 0 localhost:9000 localhost:36094 CLOSE_WAIT 14269/php5-fpm
tcp 0 0 localhost:46664 localhost:9000 FIN_WAIT2 -
tcp 1257 0 localhost:9000 localhost:36135 CLOSE_WAIT -
tcp 1257 0 localhost:9000 localhost:36125 CLOSE_WAIT -
tcp 9 0 localhost:9000 localhost:36102 CLOSE_WAIT 14268/php5-fpm
tcp 0 0 localhost:46662 localhost:9000 FIN_WAIT2 -
tcp 745 0 localhost:9000 localhost:46644 CLOSE_WAIT -
tcp 0 0 localhost:46658 localhost:9000 FIN_WAIT2 -
tcp 1265 0 localhost:9000 localhost:46607 CLOSE_WAIT -
tcp 0 0 localhost:46672 localhost:9000 ESTABLISHED 12909/nginx: worker
tcp 1257 0 localhost:9000 localhost:36119 CLOSE_WAIT -
tcp 1265 0 localhost:9000 localhost:46613 CLOSE_WAIT -
tcp 0 0 localhost:46646 localhost:9000 FIN_WAIT2 -
tcp 1257 0 localhost:9000 localhost:36137 CLOSE_WAIT -
tcp 0 0 localhost:46670 localhost:9000 ESTABLISHED 12909/nginx: worker
tcp 1265 0 localhost:9000 localhost:46619 CLOSE_WAIT -
tcp 1336 0 localhost:9000 localhost:46668 ESTABLISHED -
tcp 0 0 localhost:46648 localhost:9000 FIN_WAIT2 -
tcp 1336 0 localhost:9000 localhost:46670 ESTABLISHED -
tcp 9 0 localhost:9000 localhost:36108 CLOSE_WAIT 14274/php5-fpm
tcp 1336 0 localhost:9000 localhost:46684 ESTABLISHED -
tcp 0 0 localhost:46674 localhost:9000 ESTABLISHED 12909/nginx: worker
tcp 1336 0 localhost:9000 localhost:46666 ESTABLISHED -
tcp 1257 0 localhost:9000 localhost:46648 CLOSE_WAIT -
tcp 1336 0 localhost:9000 localhost:46678 ESTABLISHED -
tcp 0 0 localhost:46668 localhost:9000 ESTABLISHED 12909/nginx: wo
下記(上記の出力)で強調表示されているように、「CLOSE_WAIT」と「FIN_WAIT2」のペアが多数あります。
tcp 1337 0 localhost:9000 localhost:46680 CLOSE_WAIT -
tcp 0 0 localhost:46680 localhost:9000 FIN_WAIT2 -
上記のポート 46680 に注意してください。
mysql のスロークエリのエラーログを有効にしましたが、機能しませんでした。
現時点では、cronjob (以下のコマンドを参照) を介して php5-fpm を 1 分ごとに再起動して、すべてが「スムーズに」実行されるようにしていますが、パッチワークが嫌いなので、これを解決したいと思っています...
1 * * * * service php5-fpm restart > /dev/null
Google で徹底的に検索しましたが、助けにはなりませんでした。前述のように、これは LAN 内のテスト サーバーであり、CPU 負荷は 0.10 を超えることはなく、メモリ使用量も 25% 未満です (システムには 2GB の RAM があり、ubuntu-server がインストールされています)。そのため、私を助けるのに時間がかかる場合は、少なくともヒントをください。
ご協力ありがとうございます。
-ラフル
(注 - これは再投稿です -http://forum.nginx.org/read.php?11,127694)
更新: 答えを見つけたので、以下に掲載します。
答え1
nginxフォーラムの投稿で答えを見つけました -http://forum.nginx.org/read.php?2,127854
私の場合、答えは次のように設定することです。
request_terminate_timeout=30s
php-fpm 設定内(通常は/etc/php5/fpm/php-fpm.conf
)
30 秒以外の値も使用できることに注意してください。
メイン ファイルの値と一致させるためにこれを使用しましたphp.ini
:
max_execution_time = 30
皆さんありがとう。 :-)
答え2
私の問題は次のように解決されました:
/etc/nginx/nginx.confのhttp {セクションに次の変更を加えます
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
そしてnginxを再起動します
/etc/init.d/nginx を再起動
答え3
php 5.3 を使用している場合は、バックログを増やしてください。
php 5.2 を使用している場合は、パッチをバックポートしてバックログ サイズを 128 から増やします。
また、TCP ソケットではなく、UNIX ソケットを使用します。unix:/tmp/php5-cgi.sock (または関連するパス)
答え4
私の場合 (同じ nginx エラー メッセージ)、問題のある PHP スクリプトが実行を終了せず、何かを待機しているため、nginx が選択する php5-fpm の子がなくなります。
修理:
- 実行時間制限を追加します。他の人もこの投稿で言及しています。
request_terminate_timeout=30s
- 子供を育てます。そしてすべてがうまくいきました。
pm.max_spare_servers=16
pm.min_spare_servers=2
今ではすべてがうまく機能しています。