Front-end solution to cross-domain problem

1. nginx reverse proxy

First, nginx proxy local and remote sites

Acting local node sites, the page is not accessible from localhost start, but starting with nginx domain name.
To configure two of several proxy address, so that you can put a different address of the proxy to a different site

server {
    listen       80;
    server_name  www.aa.com aa.com;
    access_log  logs/test.access.log;
    
    location / {
        proxy_pass  http://localhost/;
    }

    location /koa1 {
        proxy_pass  http://localhost:9001/;
    }

    location /koa2 {
        proxy_pass  http://www.other.com/; 
    }
}

Secondly, we must set up a local hosts file

Add 127.0.0.1 www.aa.com aa.com

So, visit aa.com, you can complete the cross-domain access

Guess you like

Origin www.cnblogs.com/mengff/p/12063845.html