Resolve the 502 (Bad Gateway) error in nginx + php-fpm

Source: Internet
Author: User
Tags fpm

After buying an ECS, the system automatically installs nginx 1.6 + php 5.3.28 + mysql 5.5

After the PHP program is put into the ECS, the first test program access is normal and the speed is normal.

 

However, after you put the program online for access, you will gradually find that the PHP page is getting slower and slower, and the 502 bad gateway problem occurs directly.

(In the php-fpm.conf, the pm = static mode was originally set and pm. max_children = 128)

 

Analysis:

When the nginx access log is opened, the traffic volume is not high, and the average number of requests per second is less than 10 IP addresses. Therefore, the traffic volume cannot cause too many PHP requests, resulting in 502 of requests.

Turning on the php-fpm.conf log has a lot of PHP warning problems,

 

Then adjust the pm mode of php-fpm to pm = dynamic,

The code is as follows: Copy code

Pm. start_servers = 20

Pm. min_spare_servers = 5

Pm. max_spare_servers = 35

Pm. max_requests = 10000

 

After restarting php-fpm, use ps to view the php process:

Ps-ef | grep-c php-fpm
22

At the beginning, access to PHP was fast and then getting slower. Check the process again.

Ps-ef | grep-c php-fpm
28

From the log and process changes, we can conclude that it is a problem with the PHP program, which is caused by too many PHP requests. This is probably because too many PHP requests are called on the PHP page. After the problem is reported to the developer, after the developer solves the problem, no 502 error occurs on the server.

From the above configuration, we have configured the number of requests. Of course, this configuration is not the best. If you still encounter such problems, you can adjust the parameters.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.