problem description
frontend local mook data, The front-end project in http://127.0.0.1:3000/
Mook data node service in http://127.0.0.1:4003/
all cross-domain request interfaces similar to this
http. : / / 127.0.0.1 : 3000/api/activity/list
begins with / api/. How to use nginx to achieve port forwarding and solve the local cross-domain problem?
the environmental background of the problems and what methods you have tried
related codes
/ / Please paste the code text below (do not replace the code with pictures)
this is useless, how can configuration solve the problem?
server {
listen 3000;
-sharpserver_name 127.0.0.1;
location / {
proxy_pass http://127.0.0.1:4003/;
-sharprewrite /api/(.*) localhost:4003/api/$1 break;
-sharphttp://127.0.0.1:4003
-sharpproxy_pass http://127.0.0.1:4003;
-sharpadd_header "Access-Control-Allow-Origin" "*";
-sharproot /Users/member/work/mhy/ax-h5/server/;
-sharpindex index.html index.htm;
-sharpproxy_set_header Host $host;
-sharpproxy_set_header X-Real-IP $remote_addr;
-sharpproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
what result do you expect? What is the error message actually seen?
the expected result is that all interfaces starting with / api/ are forwarded to port 4003 for data