1、首先找到 Apache 配置文件 httpd.conf ,开启 Apache 头信息自定义模块:
LoadModule headers_module modules/mod_headers.so
把以上这一行的#注释符去掉(也有可能已经默认去掉了)
2、找到对应的虚拟主机配置文件,也就是需要被跨域的网站所对应的主机配置文件,具体内容示例如下:
<VirtualHost *:80>
DocumentRoot /www/web/ken_01h_net/public_html
ServerName ken.01h.net
</VirtualHost>
<Directory /www/web/ken_01h_net>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
添加一行: Header set Access-Control-Allow-Origin *
<VirtualHost *:80>
DocumentRoot /www/web/ken_01h_net/public_html
ServerName ken.01h.net
</VirtualHost>
<Directory /www/web/ken_01h_net>
Options FollowSymLinks
AllowOverride All
Require all granted
Header set Access-Control-Allow-Origin * #对所有域名开放
#Header set Access-Control-Allow-Origin http://www.01h.net #对指定域名开放
</Directory>