码迷,mamicode.com
首页 > 其他好文 > 详细

nginx的proxy_set_header

时间:2016-09-14 17:03:48      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:nginx   proxy_set_header   

nginx的变量很多其中proxy_set_header还是挺有用下面说说具体怎么用:

proxy_set_header主要用在对后全请求定义header上面,向后端的真实的请求头发送请求;

例子:

upstream abc{

   server 10.0.0.1:8080

}


upstream efg{

   server 10.0.0.2:80;

}


server_name www.abc.com


location ~^/ {

     proxy_set_header        Host  $host;

     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

     proxy_pass              http://tomcat_mystock;

     expires                 0;

     rewrite ^/abc/test.jspa?(.*) /def/ghi/hufu.jspa?$1 last;

}


location ~^/def/ghi {

     

      proxy_set_header          Host www.hufu.cn;

      proxy_pass              http://efg;

}

 

这样可以在不做302跳转的情况下实现对www.hufu.cn的请求

效果为:

请求:http://www.abc.com/abc/test.jspa?uid=00001

结果返回实际由http://www.hufu.cn/def/ghi/hufu.jspa?uid=00001 但页面返回200不做跳转

本文出自 “好好生活,快乐工作!” 博客,请务必保留此出处http://yjw1983.blog.51cto.com/265702/1852741

nginx的proxy_set_header

标签:nginx   proxy_set_header   

原文地址:http://yjw1983.blog.51cto.com/265702/1852741

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!