解决apache资源访问跨域问题

nodejs的程序使用http-server,http://127.0.0.1:8080/index.html访问本地http://127.0.0.1:81/api/xxx接口返回的资源出现跨域问题

解决方法:在虚拟主机配置中加入Header set Access-Control-Allow-Origin "http://www.xxx.com" 允许指定的域名访问

也可以直接写成Header set Access-Control-Allow-Origin *

修改后的配置为:

<VirtualHost *:81>
DocumentRoot "E:\xampp\htdocs\xxx"
ServerName localhost
Header set Access-Control-Allow-Origin *
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注