Nginx Tengine 502 Bad Gateway troubleshooting

Source: Internet
Author: User

Gsung should deal with high-concurrency access. I heard that there is a set of methods. To cope with 10 thousand concurrent requests, I got an lnmp for testing. After the installation is complete, the 1000-line concurrent access occurs, and the 502 bad gateway appears. It seems that some configuration files need to be modified accordingly. I found some relevant information on the Internet and shared it with me.

First, the server environment (lnmp) mentioned here refers to linux + nginx + php (php-cgi + php-fpm) + mysql.

502 Bad Gateway is the most frequently encountered problem in lnmp. There are also many causes. The following are the causes of the problem I have collected and their solutions.

1. php process death
The cause is that the error 502 is returned for every dynamic (php) request.
Solution: start php to "service php-fpm start" or "php installation path/php/sbin/php-fpm start"

2. Insufficient number of php-cgi Processes
The cause is that a 502 error occurs in a dynamic request, which is normal. This is because the number of php-cgi processes is insufficient when the concurrency is high.
Solution: Modify the php-fpm configuration php-fpm.conf, increase the number in 60, the max_children number settings not only depend on the server hardware configuration, but also related to the complexity of the php program, generally, the 4G memory can be set to 120-200. Modify the php-fpm reload and modify nginx to configure nginx. conf if necessary. Adjust the number of worker_processes to be equal to the number of CPUs (the default value of worker_processes is 1)

3. php-cgi process timeout
The cause is that the php process encountered a 502 error after running for a period of time. This may be because the php program did not add set_time_limit (0 ), the running time may be limited by the php-fpm settings. The second case is discussed below.
Solution: Modify the php-fpm configuration php-fpm.conf, adjust the number in 30 s to a higher value, adjust to 0 s allows unlimited time to run; if necessary, modify nginx configuration nginx. conf: Increase the parameters fastcgi_connect_timeout, fastcgi_send_timeout, and fastcgi_read_timeout.

4. Insufficient disk space
There are few causes, and the problem is: 502 error or unable to connect to the server. nginx is also dead when the server cannot be connected.
In this case, it takes a long time to start php-fpm or nginx, but the final startup fails. This is probably because the disk space is insufficient. Then you can run the following command to check the disk usage: df-lh. If the disk usage in the root directory "/" is 100%, you need to clear the disk space.
Solution: delete excessive log files and disable logs of some service components. Check the log files in the/var/log directory, nginx and php logs, and mysql logs. If the preceding directories are correct, check other directories one by one (check the/usr directory first) to delete excessive files.

Note: The same applies to Tengine.

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.