nginx.confのアップストリームブロックによって負荷分散された複数の分離されたphp-fpmサーバーを使用して、AmazonEC2でphp5を実行しようとしています。2 つの t1.micro インスタンスでテストしていますが、php ファイルを読み込もうとすると、ブラウザで 502 Bad Gateway エラーが発生します。(静的 html ファイルは問題なく動作しますが、php ファイルは動作しません。)
これが私のnginxエラーログです。
2012/07/11 12:28:21 [エラー] 18626#0: *1 recv() が失敗しました (104: ピアによって接続がリセットされました) アップストリームからの応答ヘッダーの読み取り中に、クライアント: xxx.xxx.xxx.xxx、サーバー: www.example.com、リクエスト: "GET / HTTP/1.1"、アップストリーム: "fastcgi://10.xxx.xxx.xxx:9000"、ホスト: "www.example.com"
そして時々私はこれを得る。
2012/07/11 13:25:51 [エラー] 1157#0: *4 アップストリームは、アップストリームからの応答ヘッダーの読み取り中に接続を途中で閉じました, クライアント: xxx.xxx.xxx.xxx, サーバー: www.example.com, リクエスト: "GET / HTTP/1.1"、アップストリーム: "fastcgi://10.xxx.xxx.xxx:9000"、ホスト: "www.example.com"
私はec2セキュリティグループ/ iptablesから9000ポートを開き、nginxとphp-fpmの両方でローカルIPアドレスを宣言することに時間を費やしたので、それは問題ではないと考えています. (以前は接続拒否エラーログがありました)
誰か助けてくれませんか?? 以下は私のサーバー設定と設定です。
[インスタンス 1]
- t1.micro CentOS 6.2.2
- nginx/1.2.2
[インスタンス 2]
- t1.micro CentOS 6.2.2
- PHP 5.3.14 (fpm-fcgi) Zend エンジン v2.3.0 と eAccelerator v0.9.6
[nginx.conf]
user nginx nginx;
worker_processes 1;
worker_rlimit_nofile 1024;
worker_priority -5;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
multi_accept on;
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_tokens off;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 0;
gzip on;
upstream apserver {
ip_hash;
server ip-10-xxx-xxx-xxx.ap-northeast-1.compute.internal:9000;
}
include /etc/nginx/conf.d/*.conf;
}
[example.conf]
server {
listen 80;
server_name www.example.com;
charset utf-8;
access_log /var/log/nginx/www.example.com.access.log main;
error_log /var/log/nginx/www.example.com.error.log debug;
root /var/www;
location / {
index index.php index.html index.html;
if (-f $request_filename) {
expires max;
break;
}
if (!-e $request_filename) {
rewrite ^(.+)/index\.php/(.*)$ $1/index.php?q=$2 last;
}
}
location ~ \.php$ {
fastcgi_send_timeout 10m;
fastcgi_read_timeout 10m;
fastcgi_connect_timeout 10m;
fastcgi_pass apserver;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
[php-fpm.d/www.conf]
[www]
listen = ip-10-xxx-xxx-xxx.ap-northeast-1.compute.internal:9000
listen.backlog = -1
listen.allowed_clients = ip-10-yyy-yyy-yyy.ap-northeast-1.compute.internal
; Tried testing with below and got the same error
;listen = 9000
;listen.allowed_clients = any
listen.owner = prod
listen.group = prod
listen.mode = 0666
user = prod
group = prod
pm = dynamic
pm.max_children = 10
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 8
pm.max_requests = 500
request_terminate_timeout = 30
request_slowlog_timeout = 2
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_admin_flag[expose_php] = off