模块 ngx_http_ssi_module

示例
Directives
ssi
ssi_last_modified
ssi_min_file_chunk
ssi_silent_errors
ssi_types
ssi_value_length
SSI 命令
嵌入式变量

该模块是一个过滤器 在响应中处理 SSI(服务器端包含)命令 穿过它。 目前,支持的 SSI 命令列表不完整。ngx_http_ssi_module

示例配置

location / {
    ssi on;
    ...
}

Directives

语法: ssi on | off;
默认值:
ssi off;
上下文: http, , ,serverlocationif in location

启用或禁用响应中 SSI 命令的处理。

语法: ssi_last_modified on | off;
默认值:
ssi_last_modified off;
上下文: http, ,serverlocation

该Directives出现在版本 1.5.1 中。

允许保留 “Last-Modified” 报头字段 在 SSI 处理期间从原始响应 以促进响应缓存。

默认情况下,标头字段将作为响应的内容删除 在处理过程中被修改,并且可能包含动态生成的元素 或独立于原始响应而更改的部分。

语法: ssi_min_file_chunk size;
默认值:
ssi_min_file_chunk 1k;
上下文: http, ,serverlocation

设置存储在磁盘上的响应部分的最小值, 从此开始,使用 SendFile 发送它们是有意义的。size

语法: ssi_silent_errors on | off;
默认值:
ssi_silent_errors off;
上下文: http, ,serverlocation

如果启用,则禁止显示 “” string (如果在 SSI 处理期间发生错误)。[an error occurred while processing the directive]

语法: ssi_types mime-type ...;
默认值:
ssi_types text/html;
上下文: http, ,serverlocation

启用对具有指定 MIME 类型的响应中的 SSI 命令的处理 除了 “”之外。 特殊值 “” 与任何 MIME 类型 (0.8.29) 匹配。text/html*

语法: ssi_value_length length;
默认值:
ssi_value_length 256;
上下文: http, ,serverlocation

设置 SSI 命令中参数值的最大长度。

SSI 命令

SSI 命令具有以下通用格式:

<!--# command parameter1=value1 parameter2=value2 ... -->

支持以下命令:

block
定义可用作存根的块 在命令中。 该块可以包含其他 SSI 命令。 该命令具有以下参数:include
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
编码方法。 可能的值包括 、 和 。 默认情况下,使用。noneurlentityentity
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/" -->
    
如果 a 包含变量,则 它们的值被替换。 正则表达式可以包含位置捕获和命名捕获 稍后可以通过变量使用,例如:text
<!--# if expr="$name = /(.+)@(?P<domain>.+)/" -->
    <!--# echo var="1" -->
    <!--# echo var="domain" -->
<!--# endif -->
include
将另一个请求的结果包含在响应中。 该命令具有以下参数:
file
指定包含的文件,例如:
<!--# include file="footer.html" -->
virtual
指定包含的请求,例如:
<!--# include virtual="/remote/body.php?argument=value" -->
在一个页面上指定并由 proproxiesed 或 FastCGI/uwsgi/SCGI/gRPC 服务器并行运行。 如果需要顺序处理,则应使用 parameter 。wait
stub
一个非标准参数,该参数将 content 如果包含的请求导致空 body 或请求处理过程中发生错误,例如:
<!--# block name="one" -->&nbsp;<!--# endblock -->
<!--# include virtual="/remote/body.php?argument=value" stub="one" -->
替换块内容在包含的请求上下文中进行处理。
wait
一个非标准参数,指示等待请求完全 complete ,然后再继续 SSI 处理,例如:
<!--# include virtual="/remote/body.php?argument=value" wait="yes" -->
set
一个非标准参数,用于指示写入成功结果 对指定变量的请求处理, 例如:
<!--# include virtual="/remote/body.php?argument=value" set="one" -->
响应的最大大小由 subrequest_output_buffer_size Directives (1.13.10) 设置:
location /remote/ {
    subrequest_output_buffer_size 64k;
    ...
}
在 1.13.10 版本之前,只有使用 ngx_http_proxy_modulengx_http_memcached_modulengx_http_fastcgi_module (1.5.6)、ngx_http_uwsgi_module (1.5.6)、 获取的响应结果, 和 ngx_http_scgi_module (1.5.6) modules 可以写入变量。 响应的最大大小是使用 proxy_buffer_sizememcached_buffer_sizefastcgi_buffer_size uwsgi_buffer_size 设置的。 和 scgi_buffer_size Directives。
set
设置变量的值。 该命令具有以下参数:
var
变量名称。
value
变量值。 如果赋值包含变量, 它们的值被替换。

嵌入变量

该模块支持 两个嵌入变量:ngx_http_ssi_module

$date_local
本地时区的当前时间。 格式由命令 替换为参数。configtimefmt
$date_gmt
当前时间 GMT。 格式由命令 替换为参数。configtimefmt