1234 root@test1:~# ss -tnl | grep 80
LISTEN 0 128 *:80 *:*
LISTEN 0 128 :::80 :::*
#默认时,nginx监听了IPV6的地址
针对我这里的环境,nginx只需要开启一个worker进程即可,对IPV6地址的监听也没有必要,所以做如下修改:
root@test1:~# find /etc/nginx/* -type f | xargs grep "worker_processes"
/etc/nginx/nginx.conf:worker_processes 4;
root@test1:~# vim /etc/nginx/nginx.conf
worker_processes 1; #修改为“1”
root@test1:~# find /etc/nginx/* -type f | xargs grep "listen 80"
/etc/nginx/sites-available/default:listen 80 default_server;
/etc/nginx/sites-available/default:#listen 80;
root@test1:~# vim /etc/nginx/sites-available/default
.....
server {
listen 80 default_server;
#listen [::]:80 default_server; #注释此行
root@test1:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@test1:~# /etc/init.d/nginx reload
[ ok ] Reloading nginx configuration (via systemctl): nginx.service.
优化后的结果如下:
root@test1:~# ps aux | grep nginx
root 11748 0.0 0.4 91280 5000 ? Ss 12:25 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 13031 0.0 0.3 91600 3808 ? S 16:00 0:00 nginx: worker process
root 13052 0.0 0.2 12948 2064 pts/1 S+ 16:01 0:00 grep nginx
root@test1:~# ss -tnl | grep 80
LISTEN 0 128 *:80 *:*
5.2、php优化
在这里针对php的优化,我们可以控制php5-fpm的工作进程数来达到节约资源的目的,最开始在“/etc/php5/fpm/php-fpm.conf”文件是找了半天都没有找到相关的配置选项,最后还是动用强大的find命令找到了相关的配置文件。
先来看看默认时php的启动进程数:
root@test1:~# ps aux | grep php
root 11946 0.0 1.3 93540 13996 ? Ss 12:32 0:01 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data 11949 0.0 1.0 94124 10720 ? S 12:32 0:00 php-fpm: pool www
www-data 11950 0.0 1.1 93980 12088 ? S 12:32 0:00 php-fpm: pool www
root 13124 0.0 0.2 12948 2204 pts/1 S+ 16:06 0:00 grep php
默认时php也开启了两个工作进程,这里只需要一个即可,做如下操作:
root@test1:~# find /etc/php5/* -type f | xargs grep "max_children" #查找有"max_children"关键字的文件
/etc/php5/fpm/pool.d/www.conf:; static - a fixed number (pm.max_children) of child processes;
/etc/php5/fpm/pool.d/www.conf:; pm.max_children - the maximum number of children that can
/etc/php5/fpm/pool.d/www.conf:; pm.max_children - the maximum number of children that
/etc/php5/fpm/pool.d/www.conf:pm.max_children = 5