question In the previous article about cross-domain resource sharing, it was mentioned that when sending cookies across domains, Access-Control-Allow-Origin cannot be set to *, and a clear domain name that is consistent with the requested web page must be specified. This kind of problem was encountered when collaborating with others during the development of this project. Solution
Implementation Reverse proxy concept The reverse proxy method refers to using a proxy server to accept connection requests on the Internet, and then forwarding the requests to the server on the internal network; and returning the results obtained from the server to the client requesting the connection on the Internet. At this time, the proxy server appears to the outside world as a server. The reverse proxy server appears to the client like the original server, and the client does not need to perform any special configuration. The client sends a normal request to the content in the reverse proxy's namespace, and the reverse proxy then determines where to forward the request (the original server) and returns the obtained content to the client, just as if the content originally belonged to it. Steps to implement cross-domain using nginx reverse proxy Go to the nginx official website to download the package and build the nginx environment Modify the nginx configuration file, find the ngixn.conf file, and modify the relevant configuration http { include mime.types; default_type application/octet-stream; sendfile on; server { listen 8000; #Listen to port 8000, you can change it to other ports server_name localhost; #Domain name of the current service location /wili/api/ { proxy_pass http://chick.platform.deva.wili.us/api/; #Add proxy configuration with access path recorded as /will/api proxy_http_version 1.1; } location / { proxy_pass http://localhost:8001; proxy_http_version 1.1; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } Configuration explanation:
Now that we have configured nginx, all accesses must go through nginx instead of the original website address (Website A localhost:8001, Website B http://chick.platform.deva.wili.us/api/). Therefore, we need to modify the request interface in website A to http://localhost:8000/wili/api/. Next, start nginx and access the configured 8000 One thing to note is that starting nginx may cause port conflicts and cause startup failure. You can check whether the startup is successful in the task manager. Summarize There are many ways to solve cross-domain browser problems:
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Example of how to implement value transfer between WeChat mini program pages
>>: How to install and configure MySQL and change the root password
Mobile browsers place web pages in a virtual "...
I believe everyone has used JD. There is a very c...
1. Network Optimization YSlow has 23 rules. These...
This article shares with you a detailed tutorial ...
The advantage of the master-slave synchronization...
This article example shares the specific code of ...
At this time, you can use overflow:auto; (when the...
Table of contents umask Umask usage principle 1. ...
Whether you are a web designer or a UI designer, ...
Introduction to four commonly used MySQL engines ...
The following information is compiled from the Int...
Mind Map He probably looks like this: Most of the...
This article is based on MySQL 8.0 This article i...
For record, it may be used in the future, and fri...
Table of contents 1. Background 2. Slow query cau...