Linux—Nginx优化—超时时间和进程管理
一.超时时间:
1.在企业网站中为了避免同一个客户长时间占用连接,造成资源浪费,可以设置相应的连接超时参数,实现对连接访问时间的控制,可以修改配置文件nginx.conf,设置keepalive_timeout超时时间
2.具体操作:
进入配置文件:
[root@localhost html]# vim /usr/local/nginx/conf/nginx.conf
keepalive_timeout 65 180;
client_header_timeout 80;
client_body_timeout 80;
重启服务:
[root@localhost html]# service nginx stop
[root@localhost html]# service nginx start
查看:
二.进程管理
在高并发的坏境中,需要启动更多的Nginx进程以保证快速响应,用以处理用户的请求,避免造成阻塞,使用ps aux查看Nginx运行的进程个数
[root@localhost html]# ps aux | grep nginx
root 54715 0.0 0.0 20556 620 ? Ss 23:18 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 54716 0.0 0.0 23072 1648 ? S 23:18 0:00 nginx: worker process
root 54802 0.0 0.0 112728 972 pts/0 R+ 23:24 0:00 grep --color=auto nginx
添加CPU:
查看CPU:
[root@localhost proc]# cat /proc/cpuinfo | grep -c "physical"
4
修改配置文件:
[root@localhost proc]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.conf
worker_processes 2;
worker_cpu_affinity 01 10;
开启服务:
[root@localhost conf]# service nginx start
查看进程数:
[root@localhost conf]# ps aux | grep nginx
root 1929 0.0 0.0 20556 616 ? Ss 23:38 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 1930 0.0 0.0 23072 1392 ? S 23:38 0:00 nginx: worker process
nginx 1931 0.0 0.0 23072 1400 ? S 23:38 0:00 nginx: worker process
root 1933 0.0 0.0 112728 972 pts/0 S+ 23:38 0:00 grep --color=auto nginx
此时就能查看到两个进程。