404 Not Found
is an error that occurs when you try to access a web page or resource that is not found on the server. Nginx is a web server and proxy server that can be used to serve websites. 404 Not Found Nginx
means that the requested page or resource was not found on the server that uses Nginx.
When a php script did not have enough RAM to execute and its process was stopped by the system, Nginx can also return a 404 error.
This is the situation you will see when the script runs for a long time, after which it returns"404 Not Found
" or your engine's error page. Usually, this fault is also visible in the debug log.
The problem is solved by freeing up memory on the server, often this can occur due to memory leaks in php, when php-fpm
processes take up almost all memory on the server. By restarting php-fpm
this problem is partially solved:
$ systemctl restart php-fpm
Is it possible to avoid this situation in the future? The answer is yes, you can. To do this, you need to configure automatic restart of processes.
To configure automatic restart of processes after a certain number of requests in Linux, you can use process management tools such as systemd
or supervisord
.
Create a file with the .service
extension in the /etc/systemd/system/
directory with your process configuration. For example, the file php-fpm.service
[Unit]
Description=PHP FastCGI Process Manager
After=network.target
[Service]
Type=simple
ExecStart=/usr/sbin/php-fpm
Restart=always
RestartSec=3
StartLimitInterval=0
StartLimitBurst=10
[Install]
WantedBy=multi-user.target
In this example, the StartLimitBurst
parameter sets the number of restarts before the process is temporarily shut down.
After creating the service file, run the command to restart systemd
and activate the new service:
sudo systemctl daemon-reload
sudo systemctl enable php-fpm.service
sudo systemctl start php-fpm.service
Install it using your Linux distribution's package manager. Then create a configuration file for your process in the /etc/supervisor/conf.d/
directory. For example, the file php-fpm.conf
:
[program:php-fpm]
command=/usr/sbin/php-fpm
autorestart=true
startretries=10
In this example, the startretries
parameter sets the number of attempts to restart the process.
After creating the configuration file, restart supervisord
:
sudo supervisorctl reread
sudo supervisorctl update
These steps will help you configure processes to restart automatically after processing a certain number of requests in Linux.