H5 development nginx cross-domain

When doing front-end development, use nginx proxy. If our current domain name and the domain name of the request interface are not under the same domain name, there will be cross-domain problems.

Open the nginx.conf file

Open Finder -Go-Go to Folder

/usr/local/etc/nginx

Generally default in this directory

After opening nginx.conf, add a location

as follows:

        location /test {
           proxy_pass https://test.stadium.***.com/**/test;
        }

Then change the baseUrl in the project to the corresponding

http://localhost/test

In this way, when requesting, the link before /test (including test itself) (here is http://localhost/test ) will be replaced with the address configured in location.

Restart nginx

sudo nginx -s reload

The cross-domain problem is solved.

Guess you like

Origin blog.csdn.net/bitcser/article/details/103896188