Home >Backend Development >PHP Problem >How to solve nginx php 499 error problem

How to solve nginx php 499 error problem

藏色散人
藏色散人Original
2021-04-02 09:03:484587browse

nginx php 499 error is because the server-side processing time is too long and the client is disconnected and waiting. The solution is to find "php-fpm.conf" on Linux and add "pm" at the bottom =dynamic" and other configurations.

How to solve nginx php 499 error problem

The operating environment of this article: nginx1.0.4 system, PHP7.1 version, DELL G3 computer

PHP and NGINX 499, 502 Problem handling

There are many reasons why nginx appears with 502, but most of the reasons can be attributed to insufficient resources.

That is to say, there is a problem with the backend php-fpm processing, and nginx will The correct client request was sent to the back-end php-fpm process,

However, due to problems with the php-fpm process, the php code could not be parsed correctly, and a 502 error was eventually returned to the client.

The reason why the server appears 502 is that the connection has timed out. We send a request to the server. Because the server currently has too many connections, the server cannot give a normal response and generate such an error.

So if your server If the amount of concurrency is very large, you can only add machines first, and then optimize as follows to achieve better results; but if you have a small concurrency but get 502, it can generally be attributed to configuration issues and script timeout issues.

The final problem is the program code itself. The processing time is too long and the resources cannot be returned! So pay attention to code optimization!

499 corresponds to "client has closed connection". This is most likely because the server-side processing time is too long and the client is disconnected from the waiting state.

If the post is submitted twice too quickly, 499 will appear. nginx considers it an unsafe connection and actively rejects the client's connection!

There is also a timeout!

Most of them say that they modify proxy_ignore_client_abort on, which means that the proxy server should not actively close the client connection. This is a situation. But it is not a solution to the problem!

The following is how I solved this problem through fpm

Control the child process, the options are static and dynamic. If static is selected, a fixed number of child processes is specified by pm.max_children. For dedicated servers, the pm value can be set to static. If you select dynamic, it is controlled by a series of parameters, that is, the dynamic process.

On Linux we find php-fpm.conf and add the following configuration at the bottom

pm = dynamic dynamic routing option configuration

pm.max_children = 16 Maximum number of child processes

pm.start_servers = 4 The number of processes at startup

pm.min_spare_servers = 2 The minimum number of idle processes. If the idle processes are less than this value, a new child process will be created

pm.max_spare_servers = 16 ensures the maximum number of idle processes. If the idle processes are greater than this value, this will be cleaned up.

I won’t go into too much detail about the static configuration. The default configuration is enough. If you want to know more, please control it on Baidu. Number of processes of php-fpm

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to solve nginx php 499 error problem. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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