Nginx 状态页
nginx提供了status模块,用于检测nginx的请求链接信息
这个功能需要在编译安装nginx的时候,添加--with-http-stud-status_module参数,才能使用
nginx -V 检查当前nginx是否支持status功能
[root@VM-4-2-centos ~]# nginx -V nginx version: nginx/1.20.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module
当支持status功能,可以添加一个conf配置文件,用于检查状态页的功能
创建一个status.conf 放入extra目录下
1、确保nginx主配置文件,支持include语法
例如: include extra/*.conf; # 将当前的extra目录下的所有conf文件,都识别是nignx的配置文件
2、创建status.conf
[root@VM-4-2-centos ~]# cd /usr/local/nginx/conf/extra/ [root@VM-4-2-centos extra]# touch status.conf
3、修改status.conf 开启状态页面功能
版本1: 验证未通过
vim status.conf
server { listen 85; location / { stub_status on; #开启状态页功能 access_log off; # 关闭访客 } }
版本2:
# 第一个虚拟主机
server { # 定义虚拟主机站点端口号 listen 80; # 填写虚拟主机的域名配置,没有域名可以写 localhost server_name learn_nginx.com; # 给nginx定义网站的编码 charset utf-8; access_log logs/learn_nginx.log; # nginx的路径匹配规则 # 如下的规则是最低级匹配,任何的nginx请求,都会进入location配置,会去定义的目录中寻找资料 location / { # root关键词 是定义网页根目录,这个html是以nginx安装的路径为相对 root /www/vod; # index关键词,定义nginx的首页文件名字,默认找index.html文件 index index.html index.htm; } # 设置nginx 状态页 location /nginx_status { stub_status on; access_log off; } }
4、检查nginx 配置 重启nginx
nginx -t nginx -s reload
5、访问nignx状态页
http://learn_nginx.com/nginx_status
显示内容如下:
Active connections: 2 # 显示正在处理的活动的,链接数 server accepts handled requests 101 101 139 Reading: 0 Writing: 1 Waiting: 1 server 表示nginx启动后一共处理的请求数 accepts handled 表示nginx启动后创建的握手数 requests 表示nginx一共处理了多少次请求 Reading:nginx 读取到客户端的 headers数量 Writing nginx 响应客户端是的headers数量 Waiting nginx 处理完毕请求之后,等待下一次的请求驻留连接数 waiting值= active-(reading+writing)
使用ab命令,对nginx进行压力测试
1、 安装ab命令
yum install httpd-tools -y
2、使用ab命令对nginx 发送大量链接
-n 请求数量 # 一共发出多少个请求 -n 1000 -c 请求并发量 -c 1000 -k 表示启动keepalive保持链接功能 ab -kc 1000 -n 100000 http://127.0.0.1