ngx_http_ssi_module 模組
範例設定 指令 ssi ssi_last_modified ssi_min_file_chunk ssi_silent_errors ssi_types ssi_value_length SSI 命令 嵌入式變數 |
ngx_http_ssi_module
模組是一個過濾器,用於處理通過它的回應中的 SSI(伺服器端包含)命令。目前,支援的 SSI 命令列表尚不完整。
範例設定
location / { ssi on; ... }
指令
語法 |
ssi |
---|---|
預設 |
ssi off; |
內容 |
http 、server 、location 、if in location |
啟用或停用回應中的 SSI 命令處理。
語法 |
ssi_last_modified |
---|---|
預設 |
ssi_last_modified off; |
內容 |
http 、server 、location |
此指令出現在 1.5.1 版本中。
允許在 SSI 處理期間保留原始回應中的「Last-Modified」標頭欄位,以方便回應快取。
預設情況下,標頭欄位會被移除,因為回應內容在處理過程中會被修改,並且可能包含動態產生的元素或與原始回應獨立變更的部分。
語法 |
ssi_min_file_chunk |
---|---|
預設 |
ssi_min_file_chunk 1k; |
內容 |
http 、server 、location |
設定回應中儲存在磁碟上的部分最小 size
,從該大小開始使用 sendfile 發送它們才有意義。
語法 |
ssi_silent_errors |
---|---|
預設 |
ssi_silent_errors off; |
內容 |
http 、server 、location |
如果啟用,則在 SSI 處理期間發生錯誤時,會抑制「[處理指令時發生錯誤]
」字串的輸出。
語法 |
ssi_types |
---|---|
預設 |
ssi_types text/html; |
內容 |
http 、server 、location |
除了「text/html
」之外,還啟用在具有指定 MIME 類型回應中處理 SSI 命令。特殊值「*
」會比對任何 MIME 類型 (0.8.29)。
語法 |
ssi_value_length |
---|---|
預設 |
ssi_value_length 256; |
內容 |
http 、server 、location |
設定 SSI 命令中參數值的最大長度。
SSI 命令
SSI 命令具有以下通用格式
<!--# command parameter1=value1 parameter2=value2 ... -->
支援以下命令
block
- 定義一個區塊,該區塊可以在
include
命令中用作存根。該區塊可以包含其他 SSI 命令。該命令具有以下參數name
- 區塊名稱。
<!--# block name="one" --> stub <!--# endblock -->
config
- 設定 SSI 處理期間使用的一些參數,即
errmsg
- 如果 SSI 處理期間發生錯誤時輸出的字串。預設情況下,會輸出以下字串
[an error occurred while processing the directive]
timefmt
- 傳遞給
strftime()
函數的格式字串,用於輸出日期和時間。預設情況下,使用以下格式
「"%A, %d-%b-%Y %H:%M:%S %Z"
%s
」格式適用於以秒為單位輸出時間。
echo
- 輸出變數的值。該命令具有以下參數
var
- 變數名稱。
encoding
- 編碼方法。可能的值包括
none
、url
和entity
。預設情況下,使用entity
。 default
- 如果變數未定義,則設定要輸出的字串的非標準參數。預設情況下,輸出「
(none)
」。命令
取代以下命令序列<!--# echo var="name" default="no" -->
<!--# if expr="$name" --><!--# echo var="name" --><!--# else -->no<!--# endif -->
if
- 執行條件包含。支援以下命令
目前僅支援一層巢狀結構。該命令具有以下參數<!--# if expr="..." --> ... <!--# elif expr="..." --> ... <!--# else --> ... <!--# endif -->
expr
- 運算式。運算式可以是
- 變數存在性檢查
<!--# if expr="$name" -->
- 將變數與文字比較
<!--# if expr="$name =
text
" --> <!--# if expr="$name !=text
" --> - 將變數與規則運算式比較
<!--# if expr="$name = /
text
/" --> <!--# if expr="$name != /text
/" -->
text
包含變數,則會替換它們的值。規則運算式可以包含位置和命名捕獲,這些捕獲稍後可以通過變數使用,例如<!--# if expr="$name = /(.+)@(?P<domain>.+)/" --> <!--# echo var="1" --> <!--# echo var="domain" --> <!--# endif -->
- 變數存在性檢查
include
- 將另一個請求的結果包含到回應中。該命令具有以下參數
file
- 指定包含的檔案,例如
<!--# include file="footer.html" -->
virtual
- 指定包含的請求,例如
在一個頁面上指定並由代理或 FastCGI/uwsgi/SCGI/gRPC 伺服器處理的多個請求會並行運行。如果需要依序處理,則應使用<!--# include virtual="/remote/body.php?argument=value" -->
wait
參數。 stub
- 一個非標準參數,用於命名區塊,如果包含的請求產生空主體,或者在請求處理期間發生錯誤,則輸出該區塊的內容,例如
替換區塊內容在包含的請求內容中處理。<!--# block name="one" --> <!--# endblock --> <!--# include virtual="/remote/body.php?argument=value" stub="one" -->
wait
- 一個非標準參數,指示在繼續 SSI 處理之前等待請求完全完成,例如
<!--# include virtual="/remote/body.php?argument=value" wait="yes" -->
set
- 一個非標準參數,指示將請求處理的成功結果寫入指定的變數,例如
回應的最大大小由 subrequest_output_buffer_size 指令設定 (1.13.10)<!--# include virtual="/remote/body.php?argument=value" set="one" -->
在 1.13.10 版本之前,只有使用 ngx_http_proxy_module、ngx_http_memcached_module、ngx_http_fastcgi_module (1.5.6)、ngx_http_uwsgi_module (1.5.6) 和 ngx_http_scgi_module (1.5.6) 模組取得的回應結果可以寫入變數。回應的最大大小使用 proxy_buffer_size、memcached_buffer_size、fastcgi_buffer_size、uwsgi_buffer_size 和 scgi_buffer_size 指令設定。location /remote/ { subrequest_output_buffer_size 64k; ... }
set
- 設定變數的值。該命令具有以下參數
var
- 變數名稱。
value
- 變數值。如果賦予的值包含變數,則會替換它們的值。
嵌入式變數
ngx_http_ssi_module
模組支援兩個嵌入式變數
$date_local
- 本機時區的目前時間。格式由
config
命令使用timefmt
參數設定。 $date_gmt
- 格林威治標準時間的目前時間。格式由
config
命令使用timefmt
參數設定。