Nginx採用模塊化的架構,Nginx中大部分功能都是經過模塊方式提供的,好比HTTP模塊、Mail模塊等。
Nginx官方模塊文檔html
--with-http_stub_status_module
提供Nginx當前處理鏈接等基本狀態信息的訪問nginx
Syntax: stub_status; Default: — Context: server, location
server { # 添加的配置 location /nginx_status { stub_status; } ...其它代碼省略... }
nginx -s reload
http://<ip>/nginx_status
,會返回以下內容Active connections: 3 server accepts handled requests 7 7 16 Reading: 0 Writing: 1 Waiting: 2
Active connections
: Nginx當前活躍連接數
accepts
: 接收客戶端鏈接的總次數
handled
: 處理客戶端鏈接的總次數。通常來講,這個參數值與accepts相同,除非已經達到了一些資源限制(例如 worker_connections限制)
requests
: 客戶端請求的總次數
Reading
: 當前nginx正在讀取請求頭的鏈接數
Writing
: 當前nginx正在寫入響應的鏈接數
Waiting
: 當前正在等待請求的空閒客戶端鏈接數。通常是在nginx開啓長鏈接(keep alive)狀況下出現。
--with-http_random_index_module
在主目錄中選擇一個隨機文件做爲主頁web
Syntax: random_index on | off; Default: random_index off; Context: location
server { location / { root /usr/share/nginx/html; #添加這一行開啓隨機主頁模塊 random_index on; #把指定的主頁註釋掉 #index index.html index.htm; } ...其它代碼省略... }
--with-ngx_http_sub_module
經過替換一個指定的字符串來修改響應shell
指定被替換的字符和替代字符瀏覽器
Syntax: sub_filter string replacement; Default: — Context: http, server, location
Last-Modified,用於校驗服務端內容是否更改,主要用於緩存場景緩存
Syntax: sub_filter_last_modified on | off; Default: sub_filter_last_modified off; Context: http, server, location
默認只替換找到的第一個字符串,若替換文本中的全部匹配的字符串,則置爲off架構
Syntax: sub_filter_once on | off; Default: sub_filter_once on; Context: http, server, location
除了「text/html」以外,還能夠用指定的MIME類型替換字符串。特殊值‘*’匹配任意MIME類型dom
Syntax: sub_filter_types mime-type ...; Default: sub_filter_types text/html; Context: http, server, location
server { location / { root /usr/share/nginx/html; index index.html; # 將首頁的nginx替換爲home sub_filter 'nginx' 'home'; # 不止替換第一個,而是替換response中全部的nginx sub_filter_once off; } ...其它代碼省略... }
nginx -s reload
curl localhost
,返回以下內容,會發現響應中全部nginx已經替換爲home[vagrant/etc/nginx]$ curl localhost <!DOCTYPE html> <html> <head> <title>Welcome to home!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to home!</h1> <p>If you see this page, the home web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://home.org/">home.org</a>.<br/> Commercial support is available at <a href="http://home.com/">home.com</a>.</p> <p><em>Thank you for using home.</em></p> </body> </html>