Server (APACHE) solves JavaScript cross-origin problems
Because the front-end has great limitations in solving cross-origin problems, we recommend that you use a server-side solution for cross-origin Ajax or IFRAME.
The principle of this solution is to send a request to the target server through the Domain Server proxy after receiving the request from the client, and return the response data to the client.
Use the mod_proxy module of Apache to enable the reverse proxy function:
1. Modify the Apache configuration file httpd. conf and remove the # sign before the following two lines.
Loadmodule proxy_module modules/mod_proxy.so
Loadmodule proxy_http_module modules/mod_proxy_http.so
2. Add the following in server config or virtual host:
Proxyrequests off
<Proxy *>
Order deny, allow
Allow from all
</Proxy>
Proxypass/folder http: // *****. com/floder
Restart Apache.
Note:
The proxyrequests off command uses a reverse (reverse) proxy. for the client, it is like the original server, and the client does not need to perform any special settings; the forward proxy allows the client to access any website and hide the client itself. Therefore, security measures must be taken to ensure that only authorized clients provide services.
The proxypass command allows a remote server to be mapped to the URL space of the local server. In this case, the local server does not act as a proxy, but acts as an image of the remote server. /Folder is a local virtual path. http: // *****. com/floder is a part of URL pointing to the remote server.
If you do not want to reverse proxy a subdirectory, you can use "! "Command. For example:
Proxypass/folder/exception!
Proxypass/folder http: // *****. com/floder
All requests except/folder/exception for http: // *****. com/floder will be proxies.
You can also use the URL rewriting method.
1. Modify the Apache configuration file httpd. conf and remove the first line #
Loadmodule proxy_module modules/mod_proxy.so
Loadmodule proxy_http_module modules/mod_proxy_http.so
Loadmodule rewrite_module modules/mod_rewrite.so
2. Add the following in server config or virtual host:
<Location/folder>
Sethandler proxy-Server
Order allow, deny
Allow from all
</Location>
Rewriteengine on
Rewriterule ^/folder/(. *) $ http: // *****. com/floder [L, r = 301, P, NC]
Note:
The location command provides URL-based access control, access to any resources under the/folder directory in the current domain will be handled by the proxy-server handler (a handler defined in the mod_proxy module) first.
The sethandler proxy-server command forces all matching files to be processed by one proxy server.
The rewriteengine on command is used to open the rewrite engine.
The rewriterule command is a rewrite rule.
Last | L this flag is used to prevent the URL that has been rewritten from being rewritten by the subsequent rules.
Redirect | r [= Code] If substitution starts with http: // thishost [: thisport]/(to make the new URL a URI), an external redirection can be executed forcibly, it is an essential medicine for cross-domain or external domain targeting. The default HTTP response code is 302. I usually specify 301.
Proxy | p this flag forces the replacement component to be sent internally as a proxy request, indicating that the rewrite passed through the mod_proxy proxy instead of the external redirection.
Nocase | NC ignores case sensitivity, that is, when pattern matches the current URL, there is no difference between 'a-Z' and 'a-Z.