1. apache静态资源跨域访问
找到apache配置文件httpd.conf
找到这行
#loadmodule headers_module modules/mod_headers.so
把#注释符去掉
loadmodule headers_module modules/mod_headers.so
目的是开启apache头信息自定义模块
在独立主机配置文件中新增header
header set access-control-allow-origin *
例如:
<virtualhost *:88> serveradmin admin@example.com documentroot "****************" servername www.jb51.com header set access-control-allow-origin * errorlog "***********" customlog "****************************" common <directory "**************"> setoutputfilter deflate options followsymlinks execcgi require all granted allowoverride all order allow,deny allow from all directoryindex index.php </directory> </virtualhost> apachecopy
意思是对这个域名的资源进行访问时,添加一个头信息
重启apache
service httpd restart
2. nginx静态资源允许跨域访问
同理 找到相应域名配置文件
在server模块中添加配置:
add_header ‘access-control-allow-origin' ‘*';
例:
server { listen 80; add_header 'access-control-allow-origin' '*'; location /roboto/ { root /home/images; autoindex on; } }
nginx重载
./nginx -s reload
通过以上方法配置完后,再次跨域访问静态资源就没有问题了
以上既是nginx/apache静态资源允许跨域访问解决方法
如对本文有疑问, 点击进行留言回复!!
5G是不是很快就能取代WiFi?两者之间的“竞争”关系真的存在吗?
带外壳版本4G LTE模块,包括华为ME909系列、移远EC20系列、移远EC200T系列
网友评论