nginx的headers_more模块的使用

nginx的headers_more模块用于 添加、修改或清除 请求/响应头,该模块不是nginx自带的,默认不包含该模块,需要另外安装。幸运的是openresty默认包含了该模块,可以直接使用。

该模块主要有4个指令

more_set_headers 用于 添加、修改、清除 响应头
more_clear_headers 用于 清除 响应头
more_set_input_headers 用于 添加、修改、清除 请求头
more_clear_input_headers 用于 清除 请求头
以下是使用示例:

1. 删除响应头
去掉X-Powered-By 和 Server响应头:

more_clear_headers X-Powered-By Server;
删除前:

删除后:

2.自定义响应头

去掉X-Powered-By响应头,增加一个X-Author响应头,修改Server响应头为Apache,伪装一下。

more_clear_headers X-Powered-By;
more_set_headers "X-Author: Lcy" "Server: Apache 2.4";
效果:

 3. 修改请求头

把query_string 中的cid参数改写成Cookie。

if ($arg_cid) {
more_set_input_headers "Cookie: PHPSESSID=$arg_cid";
}
效果如下: 

 

4.参考
该模块的详细文档可参考 headers-more-nginx-module 。
---------------------
作者:chunyuan314
来源:CSDN
原文:https://blog.csdn.net/chunyuan314/article/details/81737303
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-03-07 11:14  dream_fly_info  阅读(6084)  评论(0编辑  收藏  举报