nginx配置的server段:

        listen 8888;
server_name wyc.com;
location /user {
proxy_set_header HOST fake.com;
proxy_set_header X-Real-IP 8.8.8.8;
proxy_set_header X-Forwarded-For 8.8.8.8,9.9.9.9;
proxy_pass http://wyc.com:8888/name;
}
location /name {
echo $host;
echo $proxy_add_x_forwarded_for;
echo $remote_addr;
}

如果直接调用http://wyc.com:8888/name 返回

localhost
127.0.0.1
127.0.0.1

将HOST修改为一个欺骗的host发送给代理服务器,调用http://wyc.com:8888/user

fake.com
8.8.8.8,9.9.9.9, 127.0.0.1
127.0.0.1

自定义header头

自定义的header头www,会默认被proxy_pass到后端,如果header头aaa是依赖于其他的header头而改变:例如取决于另一个header头xyz的值。

规则: $http_自定义header名 这里要注意 header名要都转成小写 中划线改成下划线

            proxy_set_header www  "2223";
proxy_set_header aaa $http_xyz;

请求:

curl -X GET \
http://wyc.com:8888/wuyachao \
-H 'cache-control: no-cache' \
-H 'token: 3be0f904-ab22-5a9d-d389-57e584f30097' \
-H 'user: wyc' \
-H 'xyz: 123456'

结果:

{
"x-forwarded-for": "127.0.0.1",
"connection": "close",
"user": "wyc",
"accept-language": "zh-CN,zh;q=0.8,en;q=0.6",
"x-real-ip": "127.0.0.1",
"cache-control": "no-cache",
"host": "wwyycc.com",
"accept-encoding": "gzip, deflate",
"accept": "*/*",
"www": "2223",
"token": "aa68b268-a56d-5687-5542-9659c0b54bd4",
"xyz": "123456",
"aaa": "123456",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"
}

nginx的proxy_set_header的更多相关文章

  1. nginx反向代理配置(nginx.conf+proxy_set_header)

    转载:https://blog.csdn.net/bjsunwei/article/details/62231209 location / { proxy_pass http://test; prox ...

  2. 【转】nginx中proxy_set_header Host $host的作用

    nginx为了实现反向代理的需求而增加了一个ngx_http_proxy_module模块.其中proxy_set_header指令就是该模块需要读取的配置文件.在这里,所有设置的值的含义和http请 ...

  3. nginx.conf各参数的意义

    搬运+翻译至 http://qiita.com/syou007/items/3e2d410bbe65a364b603 /etc/nginx/nginx.conf 记录各个参数的意义 user user ...

  4. [Redmine] Centos5上安装Redmine3.0+nginx+thin部署

    项目管理的需要所以安装Redmine,其实wiki放在上面也不错的. 首先是安装,ruby应用第一次装,把坑记住. nginx, mysql是已经安装好的,只需要配置, 结合nginx的部署方式很多, ...

  5. Nginx里Header修改

    有时候,我们可能有修改Nginx默认Header的需求.本文就将常见的方法列出来供大家参考. 修改普通请求的Header Nginx内置的模块暂时仅支持修改响应头,使用add_header.其中: a ...

  6. NGINX 安装于配置

    just a simple example, for more information -> http://nginx.org/en/docs/.1.vi /etc/yum.repos.d/ng ...

  7. Nginx反向代理时tomcat日志获取真实IP

    对于nginx+tomcat这种架构,如果后端tomcat配置保持默认,那么tomcat的访问日志里,记录的就是前端nginx的IP地址,而不是真实的访问IP.因此,需要对nginx.tomcat做如 ...

  8. nginx在使用非80端口做反向代理【转】

    设置nginx反向代理,nginx在使用非80端口做反向代理时,浏览器访问发现返回302错误 upstream jboss{ server max_fails= fail_timeout=20s; s ...

  9. NGINX负载均衡缓存配置

    环境:VMware-Workstation-12-Pro,Windows-10,CentOS-7.5,Xshell5 1 概述 如果我们的架构是前端负载均衡后端WEB集群时,可以开启nginx的缓存功 ...

随机推荐

  1. (原)Unreal 渲染模块 渲染流程

    @author:白袍小道 浏览分享随缘,评论不喷亦可.     扯淡部分: 在temp中,乱七八糟的说了下大致的UE过程.下面我们还是稍微别那么任性,一步步来吧.     UE渲染模块牵扯到场景遍历. ...

  2. pandas.read_csv to_csv参数详解

    pandas.read_csv参数整理   读取CSV(逗号分割)文件到DataFrame 也支持文件的部分导入和选择迭代 更多帮助参见:http://pandas.pydata.org/pandas ...

  3. PAT——甲级1065:A+B and C(64bit) 乙级1010一元多项式求导

    甲级1065 1065 A+B and C (64bit) (20 point(s)) Given three integers A, B and C in [−2​63​​,2​63​​], you ...

  4. Java TCP通信概念及实例

    TCP/UDP 协议 通俗解释: TCP协议和UDP协议的区别类似于电话系统和邮政系统. <1>TCP:类似于电话系统,建立双向的通信通道,确定连接,话音顺序接听. <2>UD ...

  5. Android程序猿必须警示的13个坑

        Android开发中,犯错是难免的,不犯错是不正常的,但是犯了错以后,我们必须时刻谨记这些坑,避免再次被坑,下面小编整理了13个,日常工作中,比较常见且易犯的错误,分享给大家.    1.类的 ...

  6. JAVA输出最大值和最小值

    public class MaxMin{ public static void main(String[] args) { int[] arr = new int[6]; Scanner input ...

  7. ACM-The Coco-Cola Store

    题目: Once upon a time, there is a special coco-cola store. If you return three empty bottles to the s ...

  8. Codeforces Round #357 (Div. 2) A

    A. A Good Contest time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  9. 扩展欧几里得(ex_gcd),中国剩余定理(CRT)讲解 有代码

    扩展欧几里得算法 求逆元就不说了. ax+by=c 这个怎么求,很好推. 设d=gcd(a,b) 满足d|c方程有解,否则无解. 扩展欧几里得求出来的解是 x是 ax+by=gcd(a,b)的解. 对 ...

  10. 使用java mail的网易smtp协议 发送邮件

    package com.enation.newtest; import java.security.GeneralSecurityException; import java.util.Propert ...