优化的目录:
一、更改进程数
二、配置网页压缩
三、配置防盗链
一、更改进程数
在高并发环境中,需要启动更多的nginx进程以保证快速响应,用以处理用户的请求,避免造成阻塞。使用ps aux命令查看Nginx运行的进程的个数。
[root@localhost html]# ps aux | grep nginx
root 10825 0.0 0.0 20544 616 ? Ss 16:53 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 10826 0.0 0.0 23072 1404 ? S 16:53 0:00 nginx: worker process
root 10842 0.0 0.0 112728 968 pts/1 S+ 16:53 0:00 grep --color=auto nginx
其中master process是主进程,开启了一个,worker process是子进程,也是开启了一个
(1)修改nginx的文件中的worker_process参数,一般设为CPU的个数或核数,在高并发的情况下,可设置为CPU的个数或者核数的2倍,可以先查看CPU的核数以确定参数。
[root@localhost ~]# cat /proc/cpuinfo | grep -c "physical"
2
参数设置为2,和CPU核数相同,运行进程数设置多一些,响应客户端请求时,Nginx就不会临时启动新的进程提供服务,减少了系统的开销,提升了服务的速度。