Error 502 in nginx + php5-fpm

I have some error with subj. The server is not loaded with high load: ~ 15% of the CPU, there are several GB of memory, the hard disk does not work. But error 502 is thrown in about 3% of cases.

Programs: Debian 6, nginx / 0.7.62, php5-fpm (5.3.3-1).

The .log nginx error has this error:

connect() to unix:/var/run/php5-fpm.sock failed 

The state of php5-fpm usually looks like this:

 accepted conn: 41680 pool: www process manager: dynamic idle processes: 258 active processes: 1 total processes: 259 

I think this average load is small.

I increased the backlog parameters: in sysctl - net.core.somaxconn = 5000, in the php-fpm pool - listen.backlog = 5000. No effect.

I quote the configuration:

/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 pool

 [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 

What can I do to optimize this system and use all server resources?

PS. Sorry, my English is bad.

+43
php nginx fastcgi
May 6 '12 at 11:18
source share
4 answers

The problem is the socket itself, its problems when dealing with heavy loads are well known. Please consider using a TCP \ IP connection instead of a unix socket, for which you need to make the following changes:

  • in the php-fpm configuration configuration replace listen = /var/run/php5-fpm.sock with listen = 127.0.0.1:7777
  • in / etc / nginx / php_location replace fastcgi_pass unix:/var/run/php5-fpm.sock; on fastcgi_pass 127.0.0.1:7777;
+102
May 6, '12 at 13:20
source share

In Centos 7, Plesk 12.5

I had this problem after my harddisc entered the full version and some services failed. Other domains work fine, but none of them not only gave me 502, but also resembled timeouts. From Errorlog:

 [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 

To solve this problem, I had to (first make the space available, and then) restart php-fpm and nginx - then this error disappeared!

+2
Mar 22 '16 at 1:03
source share

The only reason this file was not created is to configure it for / etc / php -fpm.d / www.conf

Change listening = 127.0.0.1:9000

With listen = / var / run / php-fpm / php-fpm.sock

And then restart nginx and php-fpm

0
Mar 22 '17 at 6:10
source share

I have the same problem, but I did not want to switch from sockets to TCP / IP. Restarting php-fpm and nginx will solve the problem.

 sudo /etc/init.d/php-fpm restart sudo /etc/init.d/nginx restart 
-6
Jul 26 '14 at 4:04 on
source share



All Articles