在高并发环境中,需要启动更多的Nginx进程以保证快速响应,用以处理用户的请求,避免造成阻塞,使用 ps aux 命令查看Nginx运行进程的个数
其中 master process 是Nginx的主进程,开启了1个,worker process 是子进程,
也是开启了1个。
修改Nginx的配置文件中的work_processes 参数,一般设为CPU的个数或者核数,在高并发的情况下可设置为CPU的个数或者核数的2倍,可以先查看CPU的核数以确定参数。
[root@localhost html]# cat /proc/cpuinfo | grep -c "physical"8[root@localhost html]# ps aux | grep nginx //cpu 核数
root 697190.00.020544620? Ss 17:400:00 nginx: master process /usr/local/nginx/sbin/nginx //一个主进程中包含一个字进程
nobody 697200.00.0230721392? S 17:400:00 nginx: worker process
root 701970.00.0112724988 pts/0 S+18:310:00 grep --color=auto nginx
[root@localhost html]# vim /usr/local/nginx/conf/nginx.conf
worker_processes 2; #修改为核数相同或者2倍
work_cpu_affinity 0110; #设置每个进程由不同CPU处理
[root@localhost html]# systemctl restart nginx.service