我试图在nginx.conf上用多个分离的php-fpm服务器负载均衡上游块,在AmazonEC2上运行php5。我正在测试两个t1.micro实例,但当我尝试加载php文件时,在我的浏览器上收到502 Bad Gateway错误。 (静态HTML文件工作正常,但不能让PHP文件工作。)在ec2上运行多php-fpm服务器实例运行nginx时出现连接错误
这是我的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 sequrity groups/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)带有eAccelerator的Zend Engine v2.3.0 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
什么是日志?可能是你的PHP脚本是segfaulting。 – VBart 2012-07-11 13:39:29
日志for php-fpm?我没有收到日志级别为“通知”的php-fpm错误日志。我能够从CLI运行php文件,但是仍然有可能发生段错误? – 2012-07-11 15:49:53
您的PHP服务器上的document_root与您的Nginx服务器上的不一样吗? – 2012-07-11 18:24:47