How to solve 500, 502, 503, 504 errors in nginx

王林
Release: 2020-07-15 17:39:59
forward
10940 people have browsed it

How to solve 500, 502, 503, 504 errors in nginx

Solution:

(Recommended tutorial: nginx tutorial)

1. Solve the 500 error

1. The 500 error refers to an internal server error, that is, the server encounters an unexpected situation and cannot fulfill the request.

2. 500 errors generally have several situations:

(1) Web script errors, such as php syntax errors, lua syntax errors, etc.

(2) When the amount of access is large, too many files cannot be opened due to system resource limitations.

3. General analysis ideas:

(1) Check nginx error log, check php error log

(2) If there are too many open files, modify nginx’s worker_rlimit_nofile Parameters, use ulimit to check the system open file limit, modify /etc/security/limits.conf

(3) If it is a script problem, you need to fix the script error and optimize the code

( 4) If all kinds of optimizations are done well, but too many open files still appear, then you should consider load balancing and distribute the traffic to different servers.

2. Solve 502 and 504 errors

1. Use nginx proxy, but the back-end server fails; or the number of php-cgi processes is not enough; php execution time is long, or php-cgi The process dies; fastCGI usage, etc. will cause 502 and 504.

2, 502 means that the requested php-fpm has been executed, but it has not been completed for some reason, which ultimately leads to the termination of the php-fpm process.

Generally speaking, it is related to the settings of php-fpm.conf and the performance of php execution program. The website has a large number of visits, but the number of php-cgi processes is relatively small. For 502 errors in this situation, just increase the number of php-cgi processes.

Specifically, modify the /usr/local/php/etc/php-fpm.conf file and increase the max_children value appropriately.

This data should be set according to the configuration of your VPS or independent server. Generally, a php-cgi process occupies 20M of memory. You can calculate it yourself and increase it appropriately.
/usr/local/php/sbin/php-fpm restart Then restart.

3. 504 indicates timeout, that is, the request sent by the client does not reach the gateway, and the request does not get executable php-fpm.

3. Solve the 503 error

503 Service Temporarily Unavailable error

If the concurrency setting of a single IP is too small, a 503 error will be reported.

The above is the detailed content of How to solve 500, 502, 503, 504 errors in nginx. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!