問題描述前端本地mook數(shù)據(jù),前端項(xiàng)目在http://127.0.0.1:3000/ Mook數(shù)據(jù)的node服務(wù)在 http://127.0.0.1:4003/所有的跨域請(qǐng)求接口類似這種http://127.0.0.1:3000/api/activity/list以/api/開頭,怎么使用nginx 實(shí)現(xiàn)端口轉(zhuǎn)發(fā),解決本地跨域問題?問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法相關(guān)代碼// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)這樣寫沒用啊,怎么配置可以解決問題? 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;
}
}你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?期待的結(jié)果是所有的 /api/開頭的接口轉(zhuǎn)發(fā)到4003端口獲取數(shù)據(jù)
- 1 回答
- 0 關(guān)注
- 479 瀏覽
添加回答
舉報(bào)
0/150
提交
取消