前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nginx proxy_set_header配置覆盖

nginx proxy_set_header配置覆盖

原创
作者头像
fanspring
发布2020-05-10 12:18:38
3.3K0
发布2020-05-10 12:18:38
举报
文章被收录于专栏:iOS逆向iOS逆向

问题

当使用nginx反代时候我们经常会使用proxy_set_header来设置http头,如下面是一个常用的配置。

代码语言:txt
复制
server {
        listen  8080;
        server_name     _;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;

        location ^~ /test/ {
                proxy_set_header host $host:$server_port;
                proxy_pass http://127.0.0.1:8888;
        }

}

然而,你可能会发现,使用上面配置后,在服务端127.0.0.1:8888的抓包查看http header,发现只有host字段,没有X-Real-IP字段。

原因

其实,官方文档已经说明的很明确了

以下是关于proxy_set_header的说明

Allows redefining or appending fields to the request header passed to the proxied server. The value can contain text, variables, and their combinations. These directives are inherited from the previous level if and only if there are no proxy_set_header directives defined on the current level. By default, only two fields are redefined:

意思是location中只有在当前并没有proxy_set_header的配置时才会继承上一层的proxy_set_header的设置。

参考

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 问题
  • 原因
  • 参考
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档