Nginx + php5-fpm中的错误502
我的主题有误。服务器负载不高:大约15%的CPU,有几个Gb的内存,HDD并不忙。但是错误502大约会引发3%的情况。
程序:Debian 6,nginx / 0.7.62,php5-fpm(5.3.3-1)。
在nginx的error.log中是此错误:
connect() to unix:/var/run/php5-fpm.sock failed
php5-fpm的状态通常是这样的:
accepted conn: 41680pool: www
process manager: dynamic
idle processes: 258
active processes: 1
total processes: 259
我认为,这意味着负载不高。
我增加了积压参数:在sysctl中-net.core.somaxconn = 5000,在php-fpm池中-listen.backlog
=5000。没有效果。
我引用一个配置:
user www-data;worker_processes 8;
timer_resolution 100ms;
worker_rlimit_nofile 20240;
worker_priority -5;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
use epoll;
# multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_min_length 1100;
gzip_buffers 64 8k;
gzip_comp_level 3;
gzip_http_version 1.1;
gzip_proxied any;
gzip_types text/plain application/xml application/x-javascript text/css;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
client_max_body_size 100M;
server_tokens off;
}
fastcgi_pass unix:/var/run/php5-fpm.sock;fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_buffers 256 128k;
#fastcgi_buffer_size 16k;
#fastcgi_busy_buffers_size 256k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
include fastcgi_params;
[www]listen = /var/run/php5-fpm.sock
listen.backlog = 5000
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
user = www-data
group = www-data
pm = dynamic
pm.max_children = 1024
pm.start_servers = 64
pm.min_spare_servers = 64
pm.max_spare_servers = 128
pm.max_requests = 32000
pm.status_path = /system/php5-fpm-status
slowlog = /var/www/log/php-fpm.log.slow
chdir = /var/www
如何优化该系统并使之使用所有服务器资源?
PS。对不起,我的英语不好。
回答:
问题是套接字本身,它在高负载情况下的问题是众所周知的。请考虑使用TCP \ IP连接代替unix套接字,因为您需要进行以下更改:
- 在 替换
listen = /var/run/php5-fpm.sock
为listen = 127.0.0.1:7777
- 在 替换
fastcgi_pass unix:/var/run/php5-fpm.sock;
为fastcgi_pass 127.0.0.1:7777;
以上是 Nginx + php5-fpm中的错误502 的全部内容, 来源链接: utcz.com/qa/397964.html