本文将服务器Apache换成Nginx
在Nginx下优化对比Apache的性能。
下载Nginx源码包
wget http://nginx.org/download/nginx-1.10.3.tar.gz
下载 zlib
wget http://www.zlib.net/zlib-1.2.11.tar.gz
下载OpenSSL
wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz
将zlib openssl解压到 Nginx/src 目录下
编译安装
./configure --prefix=/usr/local/nginx --with-zlib=src/zlib --with-openssl=src/openssl
nginx启动/停止/重载
To start nginx, run the executable file. Once nginx is started, it can be controlled by invoking the executable with the -s parameter. Use the following syntax:
nginx -s signal
Where signal may be one of the following:
stop — fast shutdown
quit — graceful shutdown
reload — reloading the configuration file
reopen — reopening the log files
配置nginx fcgi代理
重启Nginx
通过 ab 模拟1000个客户端发起200000个并发请求
nginx能够接受的请求太小了。
更改worker进程的最大打开文件数限制。
再次测试
cpu及/io
内存
开始优化
修改如下配置
再次测试
cpu/io
内存
经过调节后,每秒并发达到了10K多。内存的使用也相对较少了。