Module ngx_http_ssi_module

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

Example Configuration

location / {
    ssi on;
    ...
}

Directives

Syntax:ssi on | off;
Default:ssi off;
Context:http , server , location , if in location

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

Syntax:ssi_last_modified on | off;
Default:ssi_last_modified off;
Context:http , server , location

该指令出现在版本 1.5.1 中。

允许在 SSI 处理期间从原始响应中保留“最后修改的”Headers 字段,以方便响应缓存。

默认情况下,在处理期间修改响应的内容时,会删除 Headers 字段,并且该 Headers 字段可能包含动态生成的元素或独立于原始响应而更改的部分。

Syntax:ssi_min_file_chunk size;
Default:ssi_min_file_chunk 1k;
Context:http , server , location

为磁盘上存储的响应部分设置最小size,从中开始使用sendfile发送响应。

Syntax:ssi_silent_errors on | off;
Default:ssi_silent_errors off;
Context:http , server , location

如果启用,如果在 SSI 处理期间发生错误,则禁止输出“ [an error occurred while processing the directive]”字符串。

Syntax:ssi_types mime-type ...;
Default:ssi_types text/html;
Context:http , server , location

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

Syntax:ssi_value_length length;
Default:ssi_value_length 256;
Context:http , server , location

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

SSI Commands

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

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

支持以下命令:

  • block

    • 定义一个可用作include命令中的存根的块。该块可以包含其他 SSI 命令。该命令具有以下参数:
  • name

    • block name.

Example:

<!--# 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

      • 编码方法。可能的值包括noneurlentity。默认情况下,使用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

    • 指定包含的请求,例如:
<!--# include virtual="/remote/body.php?argument=value" -->

在一页上指定并由代理服务器或 FastCGI/uwsgi/SCGI/gRPC 服务器处理的多个请求并行运行。如果需要顺序处理,则应使用wait参数。

  • stub

    • 一个非标准参数,用于在所包含的请求导致正文为空或在请求处理期间发生错误时命名将输出其内容的块,例如:
<!--# block name="one" -->&nbsp;<!--# endblock -->
<!--# include virtual="/remote/body.php?argument=value" stub="one" -->

在包含的请求上下文中处理替换块内容。

  • wait

    • 一个非标准参数,用于指示在 continue 执行 SSI 处理之前 await 请求完全完成,例如:
<!--# include virtual="/remote/body.php?argument=value" wait="yes" -->

set

 - a non\-standard parameter that instructs to write a successful result of request processing to the specified variable, for example: 
<!--# include virtual="/remote/body.php?argument=value" set="one" -->

响应的最大大小由subrequest_output_buffer_size指令(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)模块获得的响应结果写入变量。响应的最大大小是通过proxy_buffer_sizememcached_buffer_sizefastcgi_buffer_sizeuwsgi_buffer_sizescgi_buffer_size指令设置的。

  • set

    • 设置变量的值。该命令具有以下参数:
  • var

    • 变量名。

    • value

      • 可变值。如果分配的值包含变量,则将其值替换。

Embedded Variables

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

$date_local

  • 本地时区的当前时间。格式由config命令和timefmt参数设置。

$date_gmt

  • GMT 当前时间。格式由config命令和timefmt参数设置。