Y
Y
yuri--k2020-12-20 00:06:00
PHP
yuri--k, 2020-12-20 00:06:00

What can cause a 502 error?

Hello everyone, I'm trying to figure out why the site knocks out a 502 error.
The site sells digital goods, there are more than 1k items in the product table (MySQL database), when buying and adding to the cart, the availability is recalculated with an entry in memcached.
There are plenty of resources on the server, according to digitalocean analytics (peak about 7% percent and RAM). All pages of the site fly, are
given in 50-70ms, but sometimes the user throws out a 502 nginx error
Tell me where to dig to start, what and how to log, maybe there are relevant articles

I suspect a problem in the database, since the problem was discovered
recently
4 times
- indexing was done
- when updating the availability, many requests are made, maybe there is some kind of block xs
In this case, a beginner, but there are no other hands now

UDP
in the nginx / errors logs, such an error pops up

connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream

It is interesting that the error will be thrown out once every 10 minutes, then once every half an hour. Traffic is constant

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flying, 2020-12-20
@yuri--k

HTTP 502 is Bad Gateway. As you can see from the description , this means that the proxy (in your case, I will assume nginx) cannot receive a response from the upstream (php-fpm in your case). The text of an error resulted by you directly confirms it.
From this we can draw the first conclusion: php-fpm processes disappear somewhere. Since php-fpm worker processes restart the main php-fpm process even when it crashes, a few initial assumptions can be made offhand:

  1. You just don't have enough php-fpm worker processes to serve the requests you have. Check php-fpm logs and adjust pm, pm.max_children , pm.min_spare_servers
  2. Something is dropping the php-fpm processes themselves. Look at the logs of PHP itself and php-fpm for errors, fix them

Also, just watch what is happening with the php-fpm processes on your server, maybe it will give clues.
Of course, there is a chance that the problem is in something else, for example, indeed, in the database. But there is clearly not enough information available to make a decision. However, I hope that you run all heavy processes not through php-fpm, but as background processes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question