[英]Error 502 in nginx + php5-fpm
我的主題有誤。 服務器負載不高:大約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: 41680
pool: www
process manager: dynamic
idle processes: 258
active processes: 1
total processes: 259
我認為,這意味着負載不高。
我增加了積壓參數:在sysctl中-net.core.somaxconn = 5000,在php-fpm池中-listen.backlog =5000。沒有效果。
我引用一個配置:
/etc/nginx/nginx.conf
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;
}
/ etc / nginx / php_location
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;
php-fpm池
[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 = 127.0.0.1:7777
替換listen = /var/run/php5-fpm.sock
fastcgi_pass unix:/var/run/php5-fpm.sock;
與fastcgi_pass 127.0.0.1:7777;
在Centos 7上,Plesk 12.5
硬碟裝滿並且某些服務失敗后,我遇到了這個問題。 其他域無法完美運行,但其中一個域只給了我502,類似於超時。 從錯誤日志中:
[crit] 3112#0: *65746768 connect() to
unix:///var/www/vhosts/system/sub.domain.de/php-fpm.sock failed
(2: No such file or directory) while connecting to upstream
為了解決這個問題,我不得不(首先使空間可用,然后)重新啟動php-fpm和nginx-然后該錯誤消失了!
無法創建此文件的唯一原因是在/etc/php-fpm.d/www.conf中進行配置
更改監聽= 127.0.0.1:9000
使用listen = /var/run/php-fpm/php-fpm.sock
然后重啟nginx和php-fpm
我遇到同樣的問題,但不希望從套接字切換到TCP / IP。 重新啟動php-fpm和nginx將解決此問題。
sudo /etc/init.d/php-fpm restart
sudo /etc/init.d/nginx restart
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.