Score:0

Nginx + php-fpm 8.1 - 502 Bad Gateway - Site down for hours until php-fpm manually restarted

gb flag

I have a web server set up on Nginx and PHP-FPM (PHP version 8.1). It has worked fine for over a year now. Lately, I've noticed that the site would be down for hours - maybe once or twice a week. After investigating, I found that if I manually restart php-fpm sudo systemctl restart php8.1-fpm, everything starts working again. I suspect that it could be a spike in ddos attacks, because there is some guy that keeps harassing our site. It is also a higher-traffic site as well.

We have multiple sites/pools set up. Those sites continue working fine. It's just this one site where php-fpm seems to freeze up and doesn't work anymore, and won't restart automatically either.

Here are parts of my php8.1-fpm.log for that time period when the site failed:

[03-Aug-2023 22:49:30] NOTICE: [pool mysite] child 3543342 exited with code 0 after 62.878657 seconds from start
[03-Aug-2023 22:49:30] NOTICE: [pool mysite] child 3545476 started
[03-Aug-2023 22:49:33] WARNING: [pool mysite] server reached max_children setting (300), consider raising it
[03-Aug-2023 22:49:35] NOTICE: [pool mysite] child 3543761 exited with code 0 after 57.142360 seconds from start
[03-Aug-2023 22:49:35] NOTICE: [pool mysite] child 3545610 started

Here is the configuration for the site:

[mysite]
user = mysite
group = mysite
listen = /run/php/php8.1-fpm-mysite.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

pm = ondemand
pm.max_children = 300
pm.process_idle_timeout = 10s
pm.max_requests = 20

I few weeks ago, I added the following to the main php-fpm.conf file, in an attempt to restart php-fpm automatically when this happens, but that doesn't seem to be the solution:

emergency_restart_threshold=3
emergency_restart_interval=1m
process_control_timeout=5s

I'm not sure exactly what causes it or why it stops responding for one website only. However, I would like to know an automated solution or some configuration so php-fpm restarts itself when it happens.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.