下载地址
安装
下载完后解压
目录结构
- conf 配置文件目录
- html 默认网站目录
- logs 日志
- temp 临时文件
- nginx.exe 启动文件
进入conf目录,打开nginx.conf
修改端口号
选择跳转到当前目录,输入启动命令 start nginx
打开任务管理器
可以看到有一个nginx进程
访问网页
localhost:9091
over
nginx命令介绍
nginx. -s stop
快速停止,不保存相关信息
nginx -s quit
完整停止,保存相关信息
nginx -s reload
重载服务,优雅的重启;执行命令时要保证nginx在运行中
nginx -t
测试配置文件是否有错误,更新配置时,可以先执行此命令然后再重启服务器
nginx -c <path/conf>
指定配置文件加载路径
使用ab测压
需要安装apache
linux可以使用命令安装:yum - install httpd-tools
命令:ab -n 2000 -c 500 http://localhost:9091/
运行结果:
PS D:\DevEnv\nginx-1.18.0> ab -n 2000 -c 500 http://localhost:9091/
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests
Server Software: nginx/1.18.0
Server Hostname: localhost
Server Port: 9091
Document Path: /
Document Length: 612 bytes
Concurrency Level: 500
Time taken for tests: 4.595 seconds
Complete requests: 2000
Failed requests: 0
Total transferred: 1690000 bytes
HTML transferred: 1224000 bytes
Requests per second: 435.30 [#/sec] (mean)
Time per request: 1148.645 [ms] (mean)
Time per request: 2.297 [ms] (mean, across all concurrent requests)
Transfer rate: 359.20 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 22.4 0 501
Processing: 45 597 307.7 627 1177
Waiting: 1 404 259.4 565 681
Total: 45 598 307.8 627 1177
Percentage of the requests served within a certain time (ms)
50% 627
66% 644
75% 662
80% 679
90% 1125
95% 1175
98% 1176
99% 1176
100% 1177 (longest request)
PS D:\DevEnv\nginx-1.18.0>
关心数据
Requests per second: 435.30 [#/sec] (mean)
每秒处理请求数,mean是平均的意思
Time per request: 1148.645 [ms] (mean)
每次并发请求时间(所有并发):平均响应时间
Time per request: 2.297 [ms] (mean, across all concurrent requests)
每一次请求时间(并发平均):每个请求实际运行时间的平均值
Transfer rate: 359.20 [Kbytes/sec] received
平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题
由于对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,
所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数。