1. 找到配置文件 httpd.conf
#LoadModule headers_module modules/mod_headers.so
去掉#注释(开启apache头信息自定义模块)
2. 配置文件 httpd.conf
大概295行,改为 Require all granted
- 如果项目里有.htaccess文件
放入这段代码
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin: "*"
Header set Access-Control-Allow-Methods: "GET,POST,PUT,DELETE,OPTIONS"
Header set Access-Control-Allow-Headers: "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization"
</IfModule>
或者配置域名里加 Header set Access-Control-Allow-Origin “*”
<VirtualHost 10.0.0.2:80>
DocumentRoot /var/www/host.example.com
ServerName host.example.com
JkMount /webapp/* jkworker
Header set Access-Control-Allow-Origin "*"
RewriteEngine on
RewriteRule ^/otherhost http://otherhost.example.com/webapp [R,L]
</VirtualHost>
或者在httpd.conf最下面添加配置(全局配置):
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin: "*"
Header set Access-Control-Allow-Methods: "GET,POST,PUT,DELETE,OPTIONS"
Header set Access-Control-Allow-Headers: "Content-Type"
</IfModule>
- 重启apache,强刷页面,搞定!