首页 > 代码库 > nginx的proxy_set_header

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