nginx 端口转发跳转问题
在配置百度ueditor時,發現操作鏈接按鈕后,
服務器配置為
nginx ? test.xxx.com 80 ?轉發 ?tomcat ?test.xxx.com:8088,這個資源它去8088端口找,自身為80端口,瀏覽器跨域報錯
如果用test.xxx.com:8088/ueditor_ali 直接訪問是沒問題的,估計下來是nginx轉發的問題
參考:
http://blog.csdn.net/lsm135/article/details/51879453
https://www.oschina.net/question/922543_89331
#默認請求?
??? location /?
??? {???? ??
????? proxy_pass http://localhost:8080;?
??? }
我頁面都交給 nginx轉發給 tomcat,
這樣能訪問網頁http://192.168.8.3/lessmore/net,
但里面的超鏈接全是http://192.168.8.3:8080/lessmore/123.html;全帶8080,
頁面上的鏈接全部變成了“http://127.0.0.1:8080/lessmore/123.html”
點擊鏈接后,又直接訪問tomcat了,
怎么去掉8080? 并變成請求“www.xxx.cn/essmore/123.html" ?
(注意,不準www.xxx.cn:8080/essmore/123.html ?這會導致頁面跨域--端口號不一樣)
準備提問,在網上搜了下,找到了方法,如下:
(1)網站頁面中直接讀取了服務器ip和端口號。
(2)在網站服務端不能正確獲取到port.或者做重定向的時候地址總是丟掉端口(port)。
最簡單的解決方案,修改Nginx的配置文件:
??? server {
??????? listen?????? 80;
??????? server_name? www.xxx.cn;
????????server_name_in_redirect off;
?? ? ?? proxy_set_header Host $host:$server_port;
??????? proxy_set_header X-Real-IP $remote_addr;
??????? proxy_set_header REMOTE-HOST $remote_addr;
??????? proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
??? location / {
???????? proxy_pass http://***********:8080/;
??????? }
??? }
如上才是正確的配置nginx。其中的proxy_set_header Host $host:$server_port;?這一行非常關鍵。
改過之后,還是沒解決,看來不是這個問題
總結
以上是生活随笔為你收集整理的nginx 端口转发跳转问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 5G毫米波Vs毫米波通信模块
- 下一篇: 阿里巴巴天猫总裁蒋凡被认定为杭州高层次人