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

  • 来源:
  • 更新日期:2018-05-15

摘要: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

测试验证!