如何查看服務器狀態信息? 我們可以通過安裝Nginx的功能模塊,並修改Nginx的主配置文件來實現.
1.編譯安裝時使用--with-http_stub_status_module開啟狀態頁面模塊
[root@proxy ~]# tar -zxvf nginx-1.12.2.tar.gz
[root@proxy ~]# cd nginx-1.12.2
[root@proxy nginx-1.12.2]# ./configure \
> --with-http_ssl_module //開啟SSL加密功能
> --with-stream //開啟TCP/UDP代理模塊
> --with-http_stub_status_module //開啟status狀態頁面
[root@proxy nginx-1.12.2]# make && make install //編譯並安裝
2.啟用Nginx服務並查看監聽端口狀態
[root@proxy ~]# /usr/local/nginx/sbin/nginx
[root@proxy ~]# netstat -anptu | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10441/nginx
-a顯示所有端口的信息
-n以數字格式顯示端口號
-t顯示TCP連接的端口
-u顯示UDP連接的端口
-l顯示服務正在監聽的端口信息,如httpd啟動后,會一直監聽80端口
-p顯示監聽端口的服務名稱是什么(也就是程序名稱)
3.修改Nginx配置文件,定義狀態頁面
[root@proxy ~]# cat /usr/local/nginx/conf/nginx.conf
...
location /status { #啟用狀態模塊
stub_status on;
allow 192.168.2.100; #允許192.168.2.100訪問服務器
deny 192.168.2.200; #拒絕192.168.2.200訪問服務器
}
...
[root@proxy ~]# /usr/local/nginx/sbin/nginx
4.查看優化后的狀態頁面信息
[root@proxy ~]# 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:當前多少客戶端在等待服務器的響應。
結束.