虚拟主机的配置
cd /usr/local/lnmp/nginx/conf #nginx的主配置目录
vim nginx.conf
将85行的server这段拷贝粘贴到下面,去掉注释。
server {
listen 80;
server_name www.domain1.com;
location / {
root virtualhosts/domain1;
#此处用的是相对路径,从/usr/local/lnmp/nginx目录开始,在此目录下创建virtualhosts及其子目录
index index.html;
}
}
server {
listen 80;
server_name www.domain2.com;
location / {
root virtualhosts/domain2;
index index.html;
}
}
https配置
将nginx主配置文件的最后一段HTTPS server去点注释
server{
listen 443;
server_name localhost;
ssl on;
ssl_certificate cert.pem;
ssl_certificate cert.pem;#将cert.key改为cert.pem
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm index.php;#添加index.php
}
}
cd /etc/pki/tls/certs/
make cert.pem
mv cert.pem /usr/local/lnmp/nginx/conf/
nginx -t #检测配置文件是否有语法错误
在浏览器中输入:https:desktop118.example.com
对apache和nginx压力测试
一.ab
ab - Apache HTTP server benchmarking tool。#ab是apache的web服务器检测工具。(benchmark,n.基准,参照;vt.检测,用基准问题测试)
ab -c 1000 -n 1000 http://192.168.1.106/index.html #apache
ab -c 1000 -n 1000 http://192.168.1.118/index.html #nginx
#-c 1000每次并发1000个,-n 1000处理1000次
-c concurrency
Number of multiple requests to perform at a time. Default is one request at a time. #一次执行多个请求的数量。默认是一次一个。
-n requests
Number of requests to perform for the benchmarking session. The
default is to just perform a single request which usually leads to non-representative benchmarking results.#执行基准会话请求的数目,默认是只执行一个请求,这通常会导致测试结果不具有代表性。
以下分别是apache和nginx的测试结果,可以看出nginx的处理速度是apache的三倍左右
二、安装webbench
tar zxf webbench
make
make install
webbench -c 3000 -t 10 http://192.168.1.118/index.html
webbench -c 3000 -t 10 http://192.168.1.106/index.html
-c, --clients <n>
Use <n> multiple clients for benchmark. Default value is 1. #使用n多个客户端测试,默认是一个。
-t, --time <n>
Run benchmark for <n> seconds. Default value is 30.#运行基准测试n秒,默认是30秒。
由上图可以看出,nginx的速度是apache的6倍左右,而且没有失败的。