模块 ngx_http_sub_module

sub_filter
sub_filter_last_modified
sub_filter_once
sub_filter_types配置
Directives
示例

该模块是一个过滤器 通过将一个指定的字符串替换为另一个指定的字符串来修改响应。ngx_http_sub_module

默认情况下,此模块不是构建的,应使用 configuration 参数启用它。--with-http_sub_module

示例配置

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

语法: sub_filter string replacement;
默认值:
上下文: http, ,serverlocation

设置要替换的字符串和替换字符串。 匹配要替换的字符串,忽略大小写。 要替换的字符串 (1.9.4) 和替换字符串可以包含变量。 多个Directives 可以在同一配置级别 (1.9.4) 上指定。 这些Directives继承自之前的配置级别 当且仅当没有Directives时 在当前级别上定义。sub_filtersub_filter

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

该Directives出现在版本 1.5.1 中。

允许保留 “Last-Modified” 报头字段 替换时的原始响应 以促进响应缓存。

默认情况下,标头字段将作为响应的内容删除 在处理过程中被修改。

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

指示是否查找要替换的每个字符串 一次或重复。

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

在具有指定 MIME 类型的响应中启用字符串替换 除了 “”之外。 特殊值 “” 与任何 MIME 类型 (0.8.29) 匹配。text/html*