Status Code explanation
502 Bad Gateway: An invalid response was received from the upstream server when the server acting as a gateway or proxy attempted to execute the request.
504 Gateway time-out: When a server acting as a gateway or proxy attempts to execute a request, it fails to receive a response from the upstream server (the server that the URI identifies, such as HTTP, FTP, LDAP), or the secondary server (such as DNS).
502 Bad Gateway Cause analysis
submit the request to the gateway asPhp-FPM executes, but the PHP-FPM process terminates execution because some reasons have not been fulfilled. In this case, the problem is very clear, and the gateway services such as the configuration of PHP-FPM.
There are two parameters in the php-fpm.conf configuration file that you need to consider, namely Max_children and Request_terminate_timeout.
Max_children The maximum number of child processes, the maximum number of responses to PHP-FPM is reached at high concurrent requests, and 502 errors will occur for subsequent requests. You can view the current number of connections by using the netstat command.
Request_terminate_timeout Sets the time-out for a single request to expire. You should also note the Max_execution_time parameter in php.ini. The 502 error also occurs when the request is terminated.
when you accumulate a large number of PHP requests, you restart PHP-FPM release resources, but a two minutes less, 502 again to present, what is the cause of this? At this point should also consider the database, to see whether the database process has a large number of locked processes, the database deadlock caused the timeout, the front end of the continuation of the request, but the SQL statement is still waiting to release the lock, this time will restart the database service or kill to kill the deadlock SQL process.
for long-time requests, you can consider using asynchronous methods, see theResearch on PHP implementation of asynchronous operation".
504 Gateway time-out reason analysis
504 errors are generally associated with Nginx.conf configuration is concerned. Mainly related to the following parameters: Fastcgi_connect_timeout, Fastcgi_send_timeout, Fastcgi_read_timeout, Fastcgi_buffer_size, Fastcgi_ Buffers, Fastcgi_busy_buffers_size, Fastcgi_temp_file_write_size, Fastcgi_intercept_errors. In particular, the first three timeout periods. If the fastcgi buffer is too small it will cause the fastcgi process to be suspended and thus evolve to a 504 error.
Summary
1. Max_children
2. Request_terminate_timeout, Max_execution_time
3. Database
4. Does the Gateway service start as PHP-FPM
The 504 error mainly looks at nginx.conf about the configuration of gateways such as fastcgi.
reprinted from: http://www.ttlsa.com/html/3112.html
This article from "Silence" blog, reproduced please contact the author!
Nginx website 502 and 504 error analysis