ngx_http_sub_module 模組
範例設定 指令 sub_filter sub_filter_last_modified sub_filter_once sub_filter_types |
ngx_http_sub_module
模組是一個過濾器,它透過將指定的字串替換為另一個字串來修改回應。
此模組預設不會建置,應使用 --with-http_sub_module
設定參數啟用。
範例設定
location / { sub_filter '<a href="http://127.0.0.1:8080/' '<a href="https://$host/'; sub_filter '<img src="http://127.0.0.1:8080/' '<img src="https://$host/'; sub_filter_once on; }
指令
語法 |
sub_filter |
---|---|
預設 | — |
Context |
http , server , location |
設定要替換的字串和替換字串。要替換的字串會忽略大小寫進行比對。要替換的字串 (1.9.4) 和替換字串可以包含變數。可以在相同的設定層級上指定多個 sub_filter
指令 (1.9.4)。如果目前層級沒有定義 sub_filter
指令,這些指令會從先前的設定層級繼承。
語法 |
sub_filter_last_modified |
---|---|
預設 |
sub_filter_last_modified off; |
Context |
http , server , location |
此指令在 1.5.1 版本中出現。
允許在替換期間保留原始回應中的 "Last-Modified" 標頭欄位,以方便回應快取。
預設情況下,由於回應的內容在處理過程中被修改,因此會移除標頭欄位。
語法 |
sub_filter_once |
---|---|
預設 |
sub_filter_once on; |
Context |
http , server , location |
指示是否要尋找每個要替換的字串一次或重複尋找。
語法 |
sub_filter_types |
---|---|
預設 |
sub_filter_types text/html; |
Context |
http , server , location |
除了 “text/html
” 之外,還可以在具有指定 MIME 類型的回應中啟用字串替換。特殊值 “*
” 會比對任何 MIME 類型 (0.8.29)。