開啟nginx狀態監控 1.nginx的ngx_http_stub_status_module提供能夠擷取Nginx自上次啟動以來的工作狀態 的功能。 www.2cto.com 如果是編譯安裝的話,需要–with-http_stub_status_module啟用 2.該模組是基於某個server的,所以必須在server裡面 3.nginx.conf配置 01server02 {03 listen 80;04 server_name blog.xfz.com;05 index index.html index.htm index.php;06 root /data0/htdocs/blog;07 08 #limit_conn crawler 20;09 10 location ~ .*\.(php|php5)?$11 {12 #fastcgi_pass unix:/tmp/php-cgi.sock;13 fastcgi_pass 127.0.0.1:9000;14 fastcgi_index index.php;15 include fcgi.conf;16 }17 18 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$19 {20 expires 30d;21 }22 23 location ~ .*\.(js|css)?$24 {25 expires 1h;26 }27 location /nginx_status {28 stub_status on;29 access_log off;30 allow 192.168.1.1;#設定為可訪問該狀態資訊的ip31 deny all;32 } 33 log_format access '$remote_addr - $remote_user [$time_local] "$request" '34 '$status $body_bytes_sent "$http_referer" '35 '"$http_user_agent" $http_x_forwarded_for';36 access_log /data1/logs/access.log access;37 }38 其中狀態的配置 1location /nginx_status {2 stub_status on;3 access_log off;4 allow 192.168.1.1;#設定為可訪問該狀態資訊的ip5 deny all;6 } 1然後,reload一下nginx的配置2通過http://blog.xfz.com<span></span>/nginx_status 即可訪問狀態值: Active connections: 1 server accepts handled requests 14 14 21 Reading: 0 Writing: 1 Waiting: 0 解釋: active connections:nginx 正處理的活動串連數 20個。 server accepts handled requests:nginx啟動到現在共處理了 200個串連 , 成功建立 200 次握手 一般跟第一個一樣,差值為請求丟失數, 總共處理了286 次請求。 reading :nginx 讀取到用戶端的 Header 資訊數。 writing : nginx 返回給用戶端的 Header 資訊數。 waiting :開啟 keep-alive 的情況下,這個值等於 active - (reading + writing),意思就是 Nginx 已經處理完正在等候下一次請求指令的駐留串連。這個狀態資訊,從nginx啟動算起,包括重載設定檔,也會清零 也可以通過命令查看 01#netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’02 03 04 TIME_WAIT 1705ESTABLISHED 325406LAST_ACK 23607FIN_WAIT_1 64808FIN_WAIT_2 58109CLOSING 710CLOSE_WAIT 491611 12解析:13CLOSED //無串連是活動的或進行中14LISTEN //伺服器在等待進入呼叫15SYN_RECV //一個串連請求已經到達,等待確認16SYN_SENT //應用已經開始,開啟一個串連17ESTABLISHED //正常資料轉送狀態/當前並發串連數18FIN_WAIT1 //應用說它已經完成19FIN_WAIT2 //另一邊已同意釋放20ITMED_WAIT //等待所有分組死掉21CLOSING //兩邊同時嘗試關閉22TIME_WAIT //另一邊已初始化一個釋放23LAST_ACK //等待所有分組死掉