1、首先找到 Apache 配置文件 httpd.conf ,开启 Apache 头信息自定义模块:
1 | LoadModule headers_module modules /mod_headers .so |
把以上这一行的#注释符去掉(也有可能已经默认去掉了)
2、找到对应的虚拟主机配置文件,也就是需要被跨域的网站所对应的主机配置文件,具体内容示例如下:
1 2 3 4 5 6 7 8 9 | <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 *
1 2 3 4 5 6 7 8 9 10 11 | <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 > |