Nginx php 502 Bad Gateway error cause analysis

Source: Internet
Author: User
Tags fpm


Cause

1. PHP FastCGI Process count is insufficient
When the number of concurrent accesses to the website is huge, the number of php fastcgi processes is not guaranteed, because cgi works in a single thread and multiple processes, that is to say, cgi needs to process a page before continuing the next page. If the number of processes is not enough, when the access is huge, cgi processes the previous requests in line, and the subsequent requests will only be abandoned. In this case, nginx may encounter a 502 error from time to time.

2. PHP FastCGI memory is insufficient

When nginx returns a static page, this problem will not occur, because nginx directly returns a static page without php cgi processing. However, when a webpage needs to handle a large number of php complex operations, such as api collection or page collection, php requires a high level, if the configured memory is too small, it will easily cause php to crash.


Solution


Because I restarted the server several times before.

The code is as follows: Copy code

#/Etc/init. d/php-fpm start

Starting php-fpm done


The above is my solution, but I personally think it is not safe to find it again.

Script execution time timeout

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:

The code is as follows: Copy code

Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;

If the php-fpm.conf is as follows

The code is as follows: Copy code

Request_terminate_timeout = 10 s

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.