nginx修改响应头(可屏蔽后端服务器的信息:IIS,PHP等)
修改nginx反向代理请求的Header
需要使用到proxy_set_header和add_header指令。其中:
proxy_set_header 来自内置模块ngx_http_proxy_module,
用来重定义发往代理服务器服务器的请求头。参考:https://blog.csdn.net/weixin_41585557/article/details/82426784
示例:
location ^~/test/ {
proxy_pass http://127.0.0.1:8001$request_uri;
proxy_set_header host $http_host;
proxy_set_header x-real-ip $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
}
headers-more-nginx-module 模块
headers-more-nginx-module 模块用于添加、修改或清除 请求/响应头,该模块不是nginx自带的,默认不包含该模块,需要另外安装。
Github地址:https://github.com/openresty/headers-more-nginx-module
安装:
$ wget 'http://nginx.org/download/nginx-1.13.6.tar.gz'
$ tar -xzvf nginx-1.13.6.tar.gz
$ cd nginx-1.13.6/ # 假设Nginx安装在 /opt/nginx/ 目录
$ ./configure --prefix=/opt/nginx \
--add-module=/path/to/headers-more-nginx-module $ make
$ make install
在Nginx配置文件里加上:
load_module /path/to/modules/ngx_http_headers_more_filter_module.so;
该模块主要有4个指令:
more_set_headers 用于添加、修改、清除响应头
more_clear_headers 用于清除响应头
more_set_input_headers 用于添加、修改、清除请求头
more_clear_input_headers 用于清除请求头
# 示例 # set the Server output header
more_set_headers 'Server: my-server'; # set and clear output headers
location /bar {
more_set_headers 'X-MyHeader: blah' 'X-MyHeader2: foo';
more_set_headers -t 'text/plain text/css' 'Content-Type: text/foo';
more_set_headers -s '400 404 500 503' -s 413 'Foo: Bar';
more_clear_headers 'Content-Type'; # your proxy_pass/memcached_pass/or any other config goes here...
} # set output headers
location /type {
more_set_headers 'Content-Type: text/plain';
# ...
} # set input headers
location /foo {
set $my_host 'my dog';
more_set_input_headers 'Host: $my_host';
more_set_input_headers -t 'text/plain' 'X-Foo: bah'; # now $host and $http_host have their new values...
# ...
} # replace input header X-Foo *only* if it already exists
more_set_input_headers -r 'X-Foo: howdy';
nginx修改响应头(可屏蔽后端服务器的信息:IIS,PHP等)的更多相关文章
- 将正确的 HTTP 头转发给后端服务器的一些问题
Apache Software Foundation 的 HTTP 服务器项目(通常称为 Apache)是当今互联网上占据优势的 Web 服务器,它占据了 60% 以上的市场份额.Apache 服务器 ...
- Nginx 操作响应头信息的实现
前置条件:需要编译 ngx_http_headers_module 模块,才支持 header 头信息操作 add_header 意思为将自定义的头信息的添加到响应头,指令为 add_header n ...
- 【Nginx】修改响应头,根据不同请求IP重定向到不同IP
背景: 使用CAS登录的过程中会涉及到三次重定向,如果在同一个局域网内,是没有任何问题的,但如果涉及到跨网访问,这个问题就比较蛋疼了. 解决思路: 通过Nginx对要访问的系统进行代理,根据请求IP来 ...
- nginx替换响应头(重点:如何在替换时加上if判断)
在实现微信小程序内嵌非业务域名时,通过nginx做镜像网站绕过小程序业务域名检测,但有一些表单页面提交后会返回一个302状态,由响应头Location的值决定提交成功后的跳转地址.那么问题来了,这个地 ...
- nginx根据目录反向代理到后端服务器
nginx根据目录反向代理到后端不同的服务器 server { listen 80; server_name demo.domain.com; #通过访 ...
- [2014-02-19]如何移除响应头中的.net framework 版本信息 以及mvc版本信息?
先来看一个简单mvc3网站的响应头 修改Global.asax文件 在Application_Start方法中添加如下代码 MvcHandler.DisableMvcResponseHeader = ...
- nginx做反向负载均衡,后端服务器获取真实客户端ip(转)
首先,在前端nginx上需要做如下配置: location / proxy_set_hearder host $host; proxy_set_header X-forw ...
- nginx做反向负载均衡,后端服务器获取真实客户端ip
首先,在前端nginx上需要做如下配置: location / proxy_set_header host $host; proxy_set_header X-fo ...
- Nginx+upstream针对后端服务器容错的运维笔记
熟练掌握Nginx负载均衡的使用对运维人员来说是极其重要的!下面针对Nignx负载均衡upstream容错机制的使用做一梳理性说明: 一.nginx的upstream容错 1)nginx 判断节点失效 ...
随机推荐
- keepalived非争抢机制不生效【原创】
故障现象:俩台服务器设置了keepalived非争抢机制,但是发现优先级高的服务器还是会优先获取vip 利用tcpdump抓包发现只有其中一台服务器,没有另一台 tcpdump -i eth0 vrr ...
- CMU Database Systems - Query Optimization
查询优化应该是数据库领域最难的topic 当前查询优化,主要有两种思路, Rules-based,基于先验知识,用if-else把优化逻辑写死 Cost-based,试图去评估各个查询计划的cost, ...
- 在Oracle Sql Developer中查看oracle版本
输入select * from v$version; 执行即可. --END-- 2019-11-29 12:34
- SSA与ASS字幕
SSA字幕与ASS字幕 SSA全称SubStationAlpha,是由CSLow(又称Kotus)创建的一种字幕格式,用以实现比传统字幕诸如srt等格式更为复杂的功能.SSA目前的版本为v4.00.S ...
- You are using the runtime-only build of Vue where the template compiler is not available. Either pre
在升级脚手架到vue-cli3.0版本的时候出现了这个报错: [Vue warn]: You are using the runtime-only build of Vue where the tem ...
- DialogFragment: DialogFragment的一些理解
Android 自3.0版本引入了DialogFragment这个类,并推荐开发者使用这个类替代之前经常使用的Dialog类,那么DialogFragment相对于之前的Dialog究竟有什么优势呢? ...
- 000 装docker
直接参考别人的文章,经过验证,没有问题,需要网络. URL: https://www.cnblogs.com/qgc1995/archive/2018/08/29/9553572.html 我是虚拟机 ...
- vs2017在前端页面使用F12无法转到js脚本函数定义
这样设置后就可以正常使用了
- Django model中的save后的return
先给结论吧:在Django model的操作函数中,obj.save()后再执行return obj会返回obj的ID. 看例子: ... def create_session(self,bind_h ...
- LeetCode_371. Sum of Two Integers
371. Sum of Two Integers Easy Calculate the sum of two integers a and b, but you are not allowed to ...