Nginx HTTP 过滤addition模块(响应前后追加数据)

时间:2022-02-04 17:53:22

Nginx HTTP 过滤addition模块(响应前后追加数据)

Nginx HTTP 过滤addition模块(响应前后追加数据)


--with-http_addition_module 需要编译进Nginx

其功能主要在响应前或响应后追加内容

add_before_body 指令 将处理给定子请求后返回的文本添加到响应正文之前

Syntax: add_before_body uri;
Default:
Context: httpserverlocation

add_after_body 指令 

Syntax:add_after_body uri;
Default:—

Context:httpserverlocation

 addition_types 指令 指定处理的文本类型

Syntax: addition_types mime-type ...;
Default:
addition_types text/html;
Context: httpserverlocation

演示

location / {
add_before_body /before_action;
add_after_body /after_action;
addition_types *; }
location /before_action {
return "before \n ";
}
location /after_action {
return "after \n";
}