RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
解决nginx/apache静态资源跨域访问问题详解

1. apache静态资源跨域访问

滨城ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!

找到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 *

例如:


 ServerAdmin admin@example.com
 DocumentRoot "****************"
 ServerName www.jb51.com
 Header set Access-Control-Allow-Origin *

 ErrorLog "***********"
 CustomLog "****************************" common

 SetOutputFilter DEFLATE
 Options FollowSymLinks ExecCGI
 Require all granted
 AllowOverride All
 Order allow,deny
 Allow from all
 DirectoryIndex index.html index.php


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静态资源允许跨域访问解决方法


当前文章:解决nginx/apache静态资源跨域访问问题详解
文章起源:http://scyingshan.cn/article/gchhso.html