1024programmer JavaScript What are cross-domain issues and how to fix them

What are cross-domain issues and how to fix them

First of all, we use nginx as a proxy server to interact with users, so that users only need to interact on port 80, which avoids cross-domain problems, because we are all on port 80 Interactive;

Let’s take a look at the specific configuration of using nginx as a reverse proxy:

server {
         listen 80; #Listen to port 80, can be changed to other ports
         server_name localhost; # The domain name of the current service
         #charset koi8-r;
         #access_log logs/host.access.log main;
         location / {
             proxy_pass http://localhost:81;
             proxy_redirect default;
         }
 location /apis { #Add proxy configuration with access directory as /apis
 rewrite ^/apis/(.*)$ /$1 break;
 proxy_pass http://localhost:82;
   }
 #The following configuration is omitted

1. When the user sends localhost:80/, it will be forwarded to the http://localhost:81 service by nginx;

2. When the interface requests interface data , as long as it starts with /apis, it will be forwarded to the back-end interface server by nginx;

Summary: The principle of nginx to realize cross-domain is actually to put the web project and the back-end interface project into one domain In this way, there is no cross-domain problem, and then request different servers (servers that really work) according to the request address;

Recommended tutorial: “JS Tutorial”

The above is what is a cross-domain problem And how to solve the details, please pay attention to other related articles on 1024programmer.com!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/what-are-cross-domain-issues-and-how-to-fix-them/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索