ngx_http_sub_module模块基本指令整理

原创文章,转载请指明出处并保留原文url地址

本文主要针对nginx的ngx_http_sub_module模块做简单介绍,本文具体包括如下指令:sub_filter,sub_filter_once,sub_filter_types

该ngx_http_sub_module模块是一个过滤器,通过使用特定的字符串替换另外一个字符串来改变相应。

这个模块是不是默认内建模块,它应--with-http_sub_module参数启用。

配置示例

location / {

sub_filter      </head>

'</head><script language="javascript" src="$script"></script>';

sub_filter_once on;

}

Nginx原文:

The ngx_http_sub_module module is a filter that modifies a response by replacing one specified string by another.

This module is not built by default, it should be enabled with the --with-http_sub_module configuration parameter.

Example Configuration

location / {

sub_filter      </head>

'</head><script language="javascript" src="$script"></script>';

sub_filter_once on;

}

1. sub_filter

syntax:sub_filter  string  replacement;
default:
context:http, server, location

设置一个需要被改变的字符串以及一个用来替换的字符串。字符串的替换工作忽略大小写。替换字符串能包括变量

Nginx原文:

Sets a string that needs to be changed, and a replacement string. The string to be replaced is matched ignoring the case. A replacement string can contain variables.

2. sub_filter_once

syntax:sub_filter_once    on | off;
default:sub_filter_once on;
context:http, server, location

确定字符串应该被替换多少次, 一次, 还是多次

Nginx原文:

Determines how many times to look for a string to be replaced, once or several times.

3. sub_filter_types

syntax:sub_filter_types   mime-type...;
default:sub_filter_types text/html;
context:http, server, location

设置字符串替换功能在那些MIME类型的相应中有效, 除了在“text/html”相应中。 特殊的“*”将匹配任意类型的MIME类型。

Nginx原文:

Enables string replacement in responses with the specified MIME types in addition to “text/html”. The special value “*” matches any MIME type (0.8.29).

发表评论