原创文章,转载请指明出处并保留原文url地址
本文主要针对nginx的ngx_http_ssi_module模块做简单介绍,本文具体包括如下指令:ssi,ssi_min_file_chunk,ssi_silent_errors,ssi_types,ssi_value_length
ngx_http_ssi_module模块是处理由后端服务器返回response中SSI(服务器端包含)指令的一个过滤器模块。目前,支持的SSI命令是不完整的。
配置示例如下:
location / {
ssi on;
...
}
Nginx原文:
The ngx_http_ssi_module module is a filter that processes SSI (Server Side Includes) commands in responses passing through it. Currently, the list of supported SSI commands is incomplete.
Example Configuration
location / {
ssi on;
...
}
1. ssi
syntax: | ssi on | off; |
default: | ssi off; |
context: | http, server, location, if in location |
启用或禁用处理响应SSI指令。
Nginx原文:
Enables or disables processing of SSI commands in responses.
2. ssi_min_file_chunk
syntax: | ssi_min_file_chunk size; |
default: | ssi_min_file_chunk 1k; |
context: | http, server, location |
设置一个response存储在磁盘上的部分的最小尺寸,这个部分的数据将采用sendfile函数发送。
Nginx原文:
Sets the minimum size for parts of a response stored on disk, starting from which it makes sense to send them using sendfile.
3. ssi_silent_errors
syntax: | ssi_silent_errors on | off; |
default: | ssi_silent_errors off; |
context: | http, server, location |
当在处理ssi指令时若是发生错误, 允许抑制(不输出)“[an error occurred while processing the directive]”字符串。
Nginx原文:
Allows to suppress output of the string “[an error occurred while processing the directive]” if an error occurred during SSI processing.
4. ssi_types
syntax: | ssi_types mime-type...; |
default: | ssi_types text/html; |
context: | http, server, location |
使处理器处理制定除了“text/html”类型以外的MIME类型的相应的内容。 特殊值*匹配任意类型的相应。
Nginx原文:
Enables processing of SSI commands in responses with the specified MIME types in addition to “text/html”. The special value “*” matches any MIME type (0.8.29).
5. ssi_value_length
syntax: | ssi_value_length length; |
default: | ssi_value_length 256; |
context: | http, server, location |
设置SSI命令参数值的最大长度。
Nginx原文:
Sets the maximum length for values of parameters in SSI commands.
SSI Commands
Ssi命令有如下一般的格式
SSI commands have the following generic format:
<!--# command parameter1=value1 parameter2=value2 ... -->
下面的命令被支持
The following commands are supported:
block
定义一个块,可以作为在包含命令的存根。块可以包含其他SSI的命令。该命令的参数:
Defines a block that can be used as a stub in the include command. The block can contain other SSI commands. The command has the following parameter:
name
快名称
block name.
Example:
<!--# block name="one" -->
stub
<!--# endblock -->
config
设置一下ssi处理过程中的一些参数(就是配置)
Sets some parameters used during SSI processing, namely:
errmsg
定义一个字符串,如果在SSI处理发生错误。默认情况下,输出的字符串:
a string that is output if an error occurs during SSI processing. By default, the following string is output:
[an error occurred while processing the directive]
timefmt
a format string passed to the strftime() function used to output date and time. By default, the following format is used:
"%A, %d-%b-%Y %H:%M:%S %Z"
The “%s” format is suitable to output time in seconds.
echo
Outputs the value of a variable. The command has the following parameters:
var
variable name.
encoding
encoding method. Possible values include none, url, and entity. By default, entity is used.
default
non-standard parameter that sets a string to be output if a variable is undefined. By default, “none” is output. The command
<!--# echo var="name" default="no" -->
replaces the following sequence of commands:
<!--# if expr="$name" --><!--# echo var="name" --><!--#
else -->no<!--# endif -->
if
Performs a conditional inclusion. The following commands are supported:
<!--# if expr="..." -->
...
<!--# elif expr="..." -->
...
<!--# else -->
...
<!--# endif -->
Only one level of nesting is currently supported. The command has the following parameter:
expr
expression. An expression can be:
variable existence check:
<!--# if expr="$name" -->
comparison of a variable with a text:
<!--# if expr="$name = text" -->
<!--# if expr="$name != text" -->
comparison of a variable with a regular expression:
<!--# if expr="$name = /text/" -->
<!--# if expr="$name != /text/" -->
If a text contains variables, their values are substituted. A regular expression can contain positional and named captures that can later be used through variables, for example:
<!--# if expr="$name = /(.+)@(?P<domain>.+)/" -->
<!--# echo var="1" -->
<!--# echo var="domain" -->
<!--# endif -->
include
Includes the result of another request into a response. The command has the following parameters:
file
specifies an included file, for example:
<!--# include file="footer.html" -->
virtual
specifies an included request, for example:
<!--# include virtual="/remote/body.php?argument=value" -->
Several requests specified on one page and processed by proxied or FastCGI servers run in parallel. If sequential processing is desired, the wait parameter should be used.
stub
non-standard parameter that names the block whose content will be output if an included request results in an empty body or if an error occurs during request processing, for example:
<!--# block name="one" --> <!--# endblock -->
<!--# include virtual="/remote/body.php?argument=value" stub="one" -->
The replacement block content is processed in the included request context.
wait
non-standard parameter that instructs to wait for a request to fully complete before continuing with SSI processing, for example:
<!--# include virtual="/remote/body.php?argument=value" wait="yes" -->
set
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" -->
It should be noted that only the results of responses obtained using the ngx_http_proxy_module and ngx_http_memcached_module modules can be written into variables. set
Sets a value of a variable. The command has the following parameters:
var
variable name.
value
variable value. If an assigned value contains variables, their values are substituted.
Embedded Variables
The ngx_http_ssi_module module supports two embedded variables:
$date_local
current time in local time zone. The format is set by the config command with the timefmt parameter.
$date_gmt
current time in GMT. The format is set by the config command with the timefmt parameter.