I was so confused by this cross-domain problem (it was so lame at the time)
Usually the front-end request is the url is the domain name (port access 80 or 443) and the back-end service is port 8080, This time you request http://106.520.156.210:8080/vic-indoor-pc/selectAllUser will offer cross-domain problem (port)
So I in each request with unified prefix/API, request into http://106.520.156.210/api/vic-indoor-pc/selectAllUse (port must be the same as the front)
Front end sends the request: http://106.520.156.210/api/vic-indoor-pc/selectAllUse Nginx forward becomes: http://106.520.156.210:8080/vic-indoor-pc/selectAllUse
Rewrite “^/ API /(.*)$” /$1 break; rewrite “^/ API /(.*)$1 break; This is to delete the/API and then forwarded to http://106.520.156.210:8080/
location /api/vic-indoor-pc {
proxy_set_header Client-IP $Remote_addr;
proxy_pass http://106.520.156.210:8080/;
rewrite "^/api/(.*)$" /The $1 break;
}
Copy the code
I also encountered the problem of downloading Ali OSS storage across domains, which is also solved in this way. (with uniform prefix)
location /img/report {
proxy_set_header Client-IP $Remote_addr;
proxy_pass https://bilibili.oss-cn-shenzhen.aliyuncs.com/;
rewrite "^/img/(.*)$" /The $1 break;
}
Copy the code