Home >Backend Development >PHP Tutorial >Let Apache and nginx support cross-domain access
1. How to make Apache support cross-domain access?
Steps:
<code><span><</span>Directory <span>/</span><span>></span> AllowOverride <span>none</span><span>Require</span><span>all</span> granted <span>Header</span><span>set</span> Access<span>-Control</span><span>-Allow</span><span>-Origin</span><span>*</span><span><</span>/Directory<span>></span></code>
If you use the graphical interface to open the headers_module module, please pay attention to the order of the steps
(1) First use the graphical interface to enable the headers_module module function;
(2) Then modify the httpd.conf configuration file and add Header set Access-Control-Allow-Origin *
If the order is wrong, the httpd service cannot be started
2. How to make Nginx support cross-domain?
1. Enter the html directory of nginx
vim ../crossdomain.xml
Specific path: /usr/local/nginx/html/crossdomain.xml
2. Add:
<code><span><?xml version="1.0" encoding="UTF-8"?></span><span><!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"></span><span><<span>cross-domain-policy</span>></span><span><<span>allow-access-from</span><span>domain</span>=<span>"*"</span> /></span><span></<span>cross-domain-policy</span>></span></code>
to crossdomain.xml. The result is:
Note: The default /usr/local/nginx/html/crossdomain.xml does not exist.
The above has introduced how to enable Apache and nginx to support cross-domain access, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.