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 FollowSym s ExecCGI Require all granted AllowOverride All Order allow,deny Allow from all DirectoryIndex index.html 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静态资源允许跨域访问解决方法
继续阅读与本文标签相同的文章
下一篇 :
Progress发布NativeScript 4
-
光明日报:聚集高端产业 加速双向开放
2026-05-18栏目: 教程
-
绩效管理如何做?简单绩效考核管理应用分享
2026-05-18栏目: 教程
-
学再多Excel的高级技能,都不如这三款可视化特效组件有用
2026-05-18栏目: 教程
-
福特使用区块链技术来跟踪车辆行驶的“绿色里程”
2026-05-18栏目: 教程
-
抽10毫升血,筛查5种癌!多项新成果亮相中关村论坛
2026-05-18栏目: 教程
