模块 ngx_http_sub_module
| sub_filter sub_filter_last_modified sub_filter_once sub_filter_types 的配置 Directives 示例 |
这ngx_http_sub_modulemodule 是一个过滤器
通过将一个指定的字符串替换为另一个指定的字符串来修改响应。
这个模块不是默认构建的,它应该使用--with-http_sub_moduleconfiguration 参数。
示例配置
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 |
|---|---|
| 默认值: | — |
| 上下文: |
http,server,location |
设置要替换的字符串和替换字符串。
匹配要替换的字符串,忽略大小写。
要替换的字符串 (1.9.4) 和替换字符串可以包含变量。
几个sub_filterDirectives
可以在同一配置级别 (1.9.4) 上指定。
这些Directives继承自之前的配置级别
当且仅当没有sub_filterDirectives
在当前级别上定义。
| 语法: |
sub_filter_last_modified |
|---|---|
| 默认值: |
sub_filter_last_modified off; |
| 上下文: |
http,server,location |
该Directives出现在版本 1.5.1 中。
允许保留 “Last-Modified” 报头字段 替换时的原始响应 以促进响应缓存。
默认情况下,标头字段将作为响应的内容删除 在处理过程中被修改。
| 语法: |
sub_filter_once |
|---|---|
| 默认值: |
sub_filter_once on; |
| 上下文: |
http,server,location |
指示是否查找要替换的每个字符串 一次或重复。
| 语法: |
sub_filter_types |
|---|---|
| 默认值: |
sub_filter_types text/html; |
| 上下文: |
http,server,location |
在具有指定 MIME 类型的响应中启用字符串替换
除了”text/html”.
特殊值 “” 与任何 MIME 类型 (0.8.29) 匹配。*