访问apache下的静态js文件,跨域问题处理

  • 作者:未知
  • 来源:
  • 2018-05-15 15:55:22

1.修改apache/conf 目录下的httpd.conf文件: 找到LoadModule headers_module modules/mod_headers.so这一行,去掉前面的#号,如果没有这行,就在配置文件中增加上! 2.修改虚拟主机文件:apache/conf/extra/httpd-vhosts.conf...

1.修改apache/conf 目录下的httpd.conf文件:

002UASMrzy7605pjKJv15&690.jpg

找到LoadModule headers_module modules/mod_headers.so这一行,去掉前面的#号,如果没有这行,就在配置文件中增加上!

2.修改虚拟主机文件:apache/conf/extra/httpd-vhosts.conf文件:增加两行跨域配置,蓝色字体部分,如下

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/local/apache/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
Header set Access-Control-Allow-Origin *
Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, token"

</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/local/apache/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
Header set Access-Control-Allow-Origin *
Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, token"
</VirtualHost>

 

3.关闭文件,重启tomcat,

./bin/apachectl stop

./bin/apachectl start

测试验证!

免责声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,也不承认相关法律责任。如果您发现本社区中有涉嫌抄袭的内容,请发送邮件至:operations@xinnet.com进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。

免费咨询获取折扣