1)编译安装时使用–with-http_stub_status_module开启状态页面模块
- # tar -zxvf nginx-1.12.2.tar.gz
- # cd nginx-1.12.2
- # ./configure
- > –with-http_ssl_module //开启SSL加密功能
- > –with-stream //开启TCP/UDP代理模块
- > –with-http_stub_status_module //开启status状态页面
- # make && make install //编译并安装
2)启用 Nginx 服务并查看监听端口状态
ss 命令可以查看系统中启动的端口信息,该命令常用选项如下:
- -a 显示所有端口的信息
- -n 以数字格式显示端口号
- -t 显示TCP连接的端口
- -u 显示UDP连接的端口
- -l 显示服务正在监听的端口信息,如httpd启动后,会一直监听80端口
- -p 显示监听端口的服务名称是什么(也就是程序名称)
注意:在 RHEL7 系统中可以使用ss命令替代 netstat 命令,功能一样,选项一样。
- # /usr/local/nginx/sbin/nginx
- # netstat -anptu | grep nginx
- tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10441/nginx
- # ss -anptu | grep nginx
3)修改 Nginx 配置文件,定义状态页面
- # cat /usr/local/nginx/conf/nginx.conf
- … …
- location /status {
- stub_status on;
- #allow IP地址;
- #deny IP地址;
- }
- … …
- # /usr/local/nginx/sbin/nginx -s reload
4)优化后,查看状态页面信息
- # curl http://192.168.4.5/status
- Active connections: 1
- server accepts handled requests
- 10 10 3
- Reading: 0 Writing: 1 Waiting: 0
Active connections:当前活动的连接数量。
Accepts:已经接受客户端的连接总数量。
Handled:已经处理客户端的连接总数量。
(一般与accepts一致,除非服务器限制了连接数量)。
Requests:客户端发送的请求数量。
Reading:当前服务器正在读取客户端请求头的数量。
Writing:当前服务器正在写响应信息的数量。
Waiting:当前多少客户端在等待服务器的响应。