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不做跳轉

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章