nginx实现ip端口转发_nginx 怎么做端口转发
問題描述
前端本地mook數據,前端項目在http://127.0.0.1:3000/
Mook數據的node服務在 http://127.0.0.1:4003/
所有的跨域請求接口類似這種
http://127.0.0.1:3000/api/activity/list
以/api/開頭,怎么使用nginx 實現端口轉發,解決本地跨域問題?
問題出現的環境背景及自己嘗試過哪些方法
相關代碼
// 請把代碼文本粘貼到下方(請勿用圖片代替代碼)
這樣寫沒用啊,怎么配置可以解決問題?
server {
listen 3000;
#server_name 127.0.0.1;
location / {
proxy_pass http://127.0.0.1:4003/;
#rewrite /api/(.*) localhost:4003/api/$1 break;
#http://127.0.0.1:4003
#proxy_pass http://127.0.0.1:4003;
#add_header 'Access-Control-Allow-Origin' '*';
#root /Users/member/work/mhy/ax-h5/server/;
#index index.html index.htm;
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
你期待的結果是什么?實際看到的錯誤信息又是什么?
期待的結果是所有的 /api/開頭的接口轉發到4003端口獲取數據
總結
以上是生活随笔為你收集整理的nginx实现ip端口转发_nginx 怎么做端口转发的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WindowsLive™ OneCare
- 下一篇: ERC20标准代码