nginx的proxy_pass到$host的問題


做了反向代理后,由於代理服務器的nginx配置文件里有301跳轉導致我的后端ajax程序有問題了,所以需要用到下面的規則過濾掉我的反向代理

if ( $uri !~ ^/bbs/(.*)/?$ ) { //判斷如果不是我的服務
    set $rule 1$rule;
}

if ( $uri ~* [/]+(\w+)([-](\w+))?$ ) { //原來的301跳轉
    set $rule 2$rule;
}

if ( $rule = "21" ) { //原來的條件,並且不是我的服務那么執行原來的301跳轉,這樣我的后端服務的ajax請求就不會報錯了。
    rewrite ^ $uri/ permanent;
    break;
}

 

 

 

http://blog.sina.com.cn/s/blog_57c70e190100xzsr.html

 

設置proxy_host防止跨域

http://blog.csdn.net/felix_yujing/article/details/51682655 

 

反向代理后origin header丟失的問題

http://ruby-china.org/topics/33409

 

 

反向代理機器需要配置host

mwbs.test.com 192.168.0.11

 

nginx的server m.test.com配置下添加如下配置:

 

location /bbs/ {
    proxy_store off;
    proxy_redirect off;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://mwbs.test.com/;
}

並且配置下只能有這一個location,否則其他location會有優先級的問題導致該配置失效

當訪問http://m.test.com/bbs/forum/index是其實就相當於訪問了http://mwbs.test.com/forum/index

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM