On this page
Module ngx_http_sub_module
ngx_http_sub_module
模块是一个过滤器,可通过将一个指定的字符串替换为另一字符串来修改响应。
默认情况下未构建此模块,应使用--with-http_sub_module
配置参数启用它。
Example Configuration
location / {
sub_filter '<a href="http://127.0.0.1:8080/' '<a href="https://$host/';
sub_filter '<img src="http://127.0.0.1:8080/' '<img src="https://$host/';
sub_filter_once on;
}
Directives
Syntax: | sub_filter string replacement; |
Default: | — |
Context: | http , server , location |
设置要替换的字符串和替换字符串。忽略大小写匹配要替换的字符串。要替换的字符串(1.9.4)和替换字符串可以包含变量。可以在一个配置级别(1.9.4)上指定多个sub_filter
指令。当且仅当当前级别上没有定义sub_filter
指令时,这些指令才从上一级继承。
Syntax: | sub_filter_last_modified on | off; |
Default: | sub_filter_last_modified off; |
Context: | http , server , location |
该指令出现在版本 1.5.1 中。
允许在替换期间从原始响应中保留“最后修改的”Headers 字段,以方便响应缓存。
默认情况下,在处理期间修改响应的内容时,将删除 Headers 字段。
Syntax: | sub_filter_once on | off; |
Default: | sub_filter_once on; |
Context: | http , server , location |
指示是查找要替换一次还是重复替换的每个字符串。
Syntax: | sub_filter_types mime-type ...; |
Default: | sub_filter_types text/html; |
Context: | http , server , location |
在除“ text/html
”之外,还使用指定的 MIME 类型在响应中启用字符串替换。特殊值“ *
”匹配任何 MIME 类型(0.8.29)。