nginx: http_sub_module

陪她去流浪 桃子 2015年04月17日 阅读次数:2978

ngx_http_sub_module 模块是一个过滤器(filter),该过滤器把响应中的一个指定的字符串替换成另一个字符串。

该模块默认未被编译,要使能的话需要使用“--with-http-sub-module”配置参数。

示例配置

location / {
    sub_filter      </head> '</head><script language="javascript" src="$script"></script>';
    sub_filter_once on;
}

指令

语法sub_filter string replacement;
默认 
环境http, server, location

设置被替换的字符串(string)和用来替换的字符串(replacement)。

被替换的字符串(string)不区分大小写。用来替换的字符串(replacement)可以包含变量。

语法sub_filter_last_modified on | off;
默认sub_filter_last_modified off;
环境http, server, location
版本>=1.5.1

启用后,在替换期间将保留原始响应中“Last-Modified”头部字段的值不变,这有助于响应的缓存。

默认情况下,该字段会由于处理期间响应内容的被修改而导致被删除。

语法sub_filter_once on | off;
默认sub_filter_once on;
环境http, server, location

指示是进行多次替换还是只进行一次。

语法sub_filter_types mime-type ...;
默认sub_filter_types text/html;
环境http, server, location

指定该过滤器可作用于哪些MIME类型的文档之上(原文是:Enables string replacement in responses with the specified MIME types in addition to “text/html”,笔误?)。特殊值“*”匹配任何的MIME类型。(0.8.29)

这篇文章的内容已被作者标记为“过时”/“需要更新”/“不具参考意义”。

标签:nginx