AJAX cross-domain problem solution (4) - caller solves cross-domain problem

There is only one way for the caller to solve cross-domain, and that is to hide cross-domain. 
Why hide cross domain? 
The core idea of ​​hiding cross-domain is to hide cross-domain through reverse proxy to deceive the browser. 
What is a reverse proxy?
Reverse proxy means that two different urls accessing the same domain name will eventually go to two different servers through an intermediate server. 
One: Reverse proxy - Nginx is configured 
in the previous callee to resolve cross-domain, and the access request is The absolute address, the browser can see that the cross domain is carried out.
In this method, relative addresses are used, and Nginx is used for forwarding through different relative addresses, so that the address that is actually cross-domain does not appear to be cross-domain, but is forwarded to different servers through Nginx. 
example: 

  1. 1 server {
  2. 2     listen 80;
  3. 3     a.com
  4. 4
  5. 5     location / {
  6. 6         proxy_pass http://localhost:8081/;
  7. 7     }
  8. 8
  9. 9     location /ajaxserver {
  10. 10         proxy_pass http://localhost:8080/;
  11. 11     }
  12. 12 }
copy code



Result:
Visiting a.com actually visits: http://localhost:8081/
Visiting a/ajaxserver.com actually visits: http://localhost:8080/
Actually cross-domain, but reverse using nginx Proxy hides cross-domain 
2: Reverse proxy - Apache configuration 
still uses reverse proxy, but this method uses Apache, for 
example:
<VirtualHost *:80>
ServerName a.com
ProxyPass /ajaxserver http://localhost:8080/
ProxyPass / http://localhost:8081/
</VirtualHost> 
The result is the same as the Nginx configuration

 

This article is reproduced from: http://www.javaxxz.com/thread-359904-1-1.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326079791&siteId=291194637