nginx的模塊有官方模塊和第三方模塊之分javascript
經過 rpm 包安裝nginx加載的模塊有,具體能夠經過 nginx -V 進行查看php
--with-compat
--with-file-aio
--with-threads
--with-http_addition_module
--with-http_auth_request_module
--with-http_dav_module
--with-http_flv_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_mp4_module
--with-http_random_index_module
--with-http_realip_module
--with-http_secure_link_module
--with-http_slice_module
--with-http_ssl_module
--with-http_stub_status_module
--with-http_sub_module
--with-http_v2_module
--with-mail
--with-mail_ssl_module
--with-stream
--with-stream_realip_module
--with-stream_ssl_module
--with-stream_ssl_preread_module
該ngx_http_stub_status_module模塊提供對基本狀態信息的訪問。html
此模塊不是默認生成的,應該使用--with-http_stub_status_module 配置參數啓用 。java
配置nginx
編譯選項:
緩存
--with-http_stub_status_module
做用:
app
Nginx的客戶端狀態
主要用於展現當前處理連接的狀態,用於監控連接信息運維
配置語法:dom
Syntax:stub_status;
Default:——
Context:server,location
例子:
咱們編輯默認配置文件,添加本身的配置 /etc/nginx/conf.d/default.confui
location /mystatus { stub_status; }
驗證剛剛配置的語法是否正確
nginx -tc /etc/nginx/nginx.conf
重載 nginx 服務
nginx -s reload -c /etc/nginx/nginx.conf
效果查看訪問
編譯選項:
--with-http_random_index_module
做用:
主目錄中選一個隨機主頁
配置語法:
Syntax:random_index on | off;
Default:random_index off;
Context:location
例子:隨機訪問頁面
編輯默認配置文件 /etc/nginx/nginx.conf
location / { #root /usr/share/nginx/html; #index index.html index.htm; root /opt/app/code; random_index on; }
從新設置了主目錄文件,而且在主目錄下新建了html文件
檢查重啓:
nginx -tc /etc/nginx/nginx.conf systemctl reload nginx
連續刷新會看到不一樣的頁面
注意:雖然nginx會將主目錄下的文件做爲隨機主頁,可是不會將隱藏文件包括在內,Linux的隱藏文件是指以點 . 開始的文件
編譯選項:
--with-http_sub_module
做用:
HTTP內容替換
該模塊是用於Nginx服務端在給客戶端response內容的時候,進行HTTP內容更換。
語法:
Syntax:
sub_filter string replacement; (string表示要替換的內容,replacement表示替換後的對象)
Default: — Context:
http, server, location
語法:
sub_filter_last_modified on | off;
默認: sub_filter_last_modified off;
語境: http,server,location```
該模塊用於判斷每次請求的服務端內容是否發生變化,當發生變化的時候返回給客戶端,當沒有發生變化的時候,再也不返回內容。重要用於緩存。
語法: sub_filter_once on | off;
默認值: sub_filter_once on;
配置段: http, server, location
字符串替換一次仍是屢次替換,默認替換一次,例如你要替換響應內容中的ttlsa爲運維生存時間,若是有多個ttlsa出現,那麼只會替換第一個,若是off,那麼全部的ttlsa都會被替換
首先咱們編寫了一個html文件
/opt/app/code/submodule.html
<head> <meta charset="utf-8"> <title>submodules</title> </head> <body> <a>jeson</a> <a>at</a> <a>imooc</a> <a>jeson</a> <a>imooc</a> </body> </html>
default.conf
location / { #root /usr/share/nginx/html; #index index.html index.htm; root /opt/app/code; index submodule.html; sub_filter '<a>imooc' '<a>IMOOC'; }
重啓 nginx
systemctl reload nginx
訪問主頁
能夠發現默認替換的是第一次匹配的
這是由於sub_filter_once默認開啓,所以只替換了一個。
location / { #root /usr/share/nginx/html; #index index.html index.htm; root /opt/app/code; index submodule.html; sub_filter '<a>imooc' '<a>IMOOC'; sub_filter_once off; }
重啓 nginx 再次屬性頁面