nginx Too many open files error solution

In a high-concurrency scenario, the page opening speed is slow. Check the host nginx log and find that a large number of Too many open files error messages are refreshed in the error.log log. To solve this problem, you need to optimize the open files parameter of the host, and the steps are as follows.

1. Modify the host open files configuration

This restriction is only valid for non-root users, not for root user processes.
vim /etc/security/limits.conf adjusts the configuration as follows
insert image description here
and takes effect in real time after saving. After re-login to the host, ulimit -a checks the configuration as follows, and it has been successfully modified.
insert image description here

2. Optimize nginx work_connections related parameters, add worker_rlimit_nofile configuration

Worker_processes is set to the same number as the host cpu.
To view the number of host cpus, you can enter 1 with the top command.

insert image description here

3. Check nginx process limit

After optimizing the above two steps, it is still found to be invalid. It may be because the configuration of ulimit and limits.conf is only for logged-in users, and if it is started as a service.
cat /proc/pid/limits View nginx process limit configuration information
insert image description here
Refer to the following to modify the nginx service file.
https://www.bbsmax.com/A/Vx5MDR99JN

If the host has no systemctl command, only the service command needs to restart nginx to take effect. service nginx restart restart nginx

cat /etc/init.d/nginx
View the nginx service startup script, we can see that reload will retain the original pid, and restart will stop first and then start, nginx will re-read the configuration to obtain a new pid, and the configured worker_rlimit_nofile will take effect.
insert image description here

Guess you like

Origin blog.csdn.net/qq_44624722/article/details/124751970