首页 > 其他 > 详细

nginx的proxy_set_header

时间:2016-09-14 17:01:55      阅读:154      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!