The solution to the 502 error in php is: 1. Increase the number of fastcgi processes; 2. Increase the number of files opened by the Linux kernel; 3. Edit the configuration file nginx.conf and adjust the script execution time; 4. Add cache configuration to the nginx.conf configuration file.
Analysis:
This will occur if the number of php-cgi processes is not enough, the php execution time is long, or the php-cgi process dies. 502 error.
How to solve?
1. Increase the number of processes
Use netstat -napo | grep "php-fpm" | wc -l
to check the current fastcgi process The number, if the number is close to the upper limit configured in conf, you need to increase the number of processes.
But you can’t increase it endlessly. You can adjust the number of php-fpm sub-processes to 100 or more according to the server memory. On a server with 4G memory, 200 is enough.
2. Increase the number of files opened by the linux kernel
You can use these commands (must be the root account)
echo 'ulimit -HSn 65536'>> /etc/profile echo 'ulimit -HSn 65536'>> /etc/rc.local source /etc/profile
3. Adjust Script execution time
If the script waits for a long time without returning for some reason, resulting in new requests not being processed, you can appropriately adjust the following configuration.
nginx.conf The main contents are as follows:
fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300;
php-fpm.conf If the contents are as follows
request_terminate_timeout =10s
4. Add cache
Modify or add configuration to nginx.conf
proxy_buffer_size 64k; proxy_buffers 512k; proxy_busy_buffers_size 128k;
If you need to learn more knowledge, please visit php Chinese website.
The above is the detailed content of How to solve the 502 error in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
