Nginx + php-fpm error 502 bad gateway solution, nginxphp-fpm
1. nginx error cannot be found. Generally, You need to modify/usr/local/nginx/conf/nginx. conf (careful modification may cause other website problems)
Error 2,502
Case 1: nginx fails:
Command:/usr/local/nginx/sbin/nginx-s reload
Wait a moment later
Case 2: php disconnection:
First you need to modify the parameters in the/usr/local/php-5.6.0/etc/php-fpm.conf file specifically modify which to change to how much to keep trying
Then use one or more of the following commands to restart the configuration/usr/local/php-5.6.0/sbin/php-fpm reload
/Usr/local/php-5.6.0/sbin/php-fpm
/Usr/local/php-5.6.0/sbin/php-fpm-h
/Usr/local/php-5.6.0/sbin/php-fpm-t
/Usr/local/php-5.6.0/sbin/php-fpm-R
Restart nginx and wait for a while.
If the above method is not easy to use, you can try the following
1. Insufficient number of php-fpm Processes
Use netstat-napo | grep "php-fpm" | wc-l to check the number of fastcgi processes. If the number is close to the upper limit configured in conf, you need to increase the number of processes.
However, you cannot increase the number of php-fpm sub-processes to 100 or more based on the server memory.
2. Increase the number of files opened in the Linux kernel.
You can use these commands (must be a root account)
Echo 'ulimit-HSn 65536 '>/etc/profile
Echo 'ulimit-HSn 65536 '>/etc/rc. local
Source/etc/profile
3. The script execution time has timed out.
If the script does not return after a long wait for some reason, the new request cannot be processed, you can adjust the following configurations as appropriate.
Nginx. conf mainly includes the following:
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
If the php-fpm.conf is as follows
Request_terminate_timeout = 10 s
4. Relatively small cache settings
Modify or add configuration to nginx. conf
Proxy_buffer_size 64 k;
Proxy_buffers 512 k;
Proxy_busy_buffers_size 128 k;
5. recv () failed (104: Connection reset by peer) while reading response header from upstream
Possible cause: Network Packet Loss in the IDC or access to this domain name is prohibited by the hardware firewall in the IDC
But the most important thing is to set the timeout in the program. Do not use the request_terminate_timeout of php-fpm,
It is best to set it to request_terminate_timeout = 0;
Because this parameter will directly kill the php process and restart the php process, the front-end nginx will return 104: Connection reset by peer. This process is very slow. The general feeling is that the website is very stuck.
May 01 10:50:58. 044162 [WARNING] [pool www] child 4074, script'/usr/local/nginx/html/quancha/sameip/detail. php 'execution timed out (15.129933 sec), terminating
May 01 10:50:58. 045725 [WARNING] [pool www] child 4074 exited on signal 15 SIGTERM after 90.227060 seconds from start
May 01 10:50:58. 046818 [NOTICE] [pool www] child 4082 started
The most important thing about one thousand-way 10 thousand is to control the timeout in the program. For functions such as gethostbyname, curl, and file_get_contents, you must set the timeout time.
The other is to say that this is to increase the interaction of the website, but it is slow to respond when you use more. If your website times out and uses more, you can close it.