• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    解决nginx/apache静态资源跨域访问问题详解

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

    上一篇:window和linux通过tomcat9手工部署war包的方法
    下一篇:Apache下ModSecurity的安装启用与配置
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    解决nginx/apache静态资源跨域访问问题详解 解决,nginx,apache,静态,资源,