Home > Backend Development > PHP Tutorial > 502 Bad Gateway error encountered by Nginx + PHP (php-fpm)

502 Bad Gateway error encountered by Nginx + PHP (php-fpm)

WBOY
Release: 2016-07-25 08:46:48
Original
1051 people have browsed it
502 Bad Gateway error encountered by Nginx + PHP (php-fpm)

502 errors often pop up when using Nginx. Of course, errors cannot be ignored.
Nginx has just started to be used. If there are problems, there are opportunities for improvement. Let’s study the cause of the problem.
Check the error log first. The difference between Nginx and Apache is that PHP script errors will not appear in the Nginx log. So when a 502 error occurs, you must check the php-fpm log. The next article will introduce how to call it out. Specific error log of php-fpm.
By checking the error.log of php-fpm, you can find that the execution time of some PHP programs exceeds the waiting time of Nginx. You can appropriately increase the FastCGI timeout time in the nginx.conf configuration file.
According to this article
http://rtcamp.com/wordpress-nginx/tutorials/php/increase-script-execution-time/
1) Modify the execution time of the php script from 30s to 300s, modify php. ini
If you don’t know the location, you can find it from phpinfo()


In Apache, you only need to modify this step, but in Nginx, you need two more steps

2) Modify php-fpm configuration
vim /etc/php-fpm.d/www.conf
502 Bad Gateway error encountered by Nginx + PHP (php-fpm)
3) Modify Nginx configuration
vim /etc/nginx/conf.d/www.conf
502 Bad Gateway error encountered by Nginx + PHP (php-fpm)
Next, restartphp-fpm and Nginx
can see the effect.
In addition, if the number of php-cgi processes is not enough, the php execution time is long, or the php-cgi process dies, a 502 error will occur.

If you encounter any technical problems that are not solved in time during the learning process, we recommend a good WeChat public account: [Tuosheng Technology] There will be professional technical personnel to solve it for you.
[Tuosheng Technology] focuses on sharing the most comprehensive video learning materials and learning experiences on programming development. Currently, Java, Android, UID , PHP , iOS and other instructional videos,



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template