CDN加速跨域问题
By skyshappiness Posted 2017-06-28 15:49:09 In

一、背景:

搭建 CDN 静态资源加速时,单独成立静态文件项目,单独配置域名后,产生跨域问题。


二、解决方案:

    Apache:

        1.开启 mod_headers 模块
            LoadModule headers_module modules/mod_headers.so

        2.修改 <VirtualHost> 配置

            <VirtualHost *:8082>
                ServerAdmin webmaster@dummy-host2.example.com
                DocumentRoot "D:\XXX\XXX\XXX\XXX"
                ServerName dummy-host2.example.com
                <Directory "D:\XXX\XXX\XXX\XXX">
                    Options FollowSymLinks ExecCGI
                    AllowOverride All
                    Order allow,deny
                    Allow from all
                    Require all granted
                </Directory>
                ErrorLog "logs/dummy-host2.example.com-error.log"

                CustomLog "logs/dummy-host2.example.com-access.log" common

            </VirtualHost>


    nginx:

        1.在 静态资源指向中加入配置代码:

            location ~* \.(eot|ttf|woff|woff2|svg|otf)$ {                //其中 eot|ttf|woff|woff2|svg|otf 为允许访问的文件后缀
                 add_header Access-Control-Allow-Origin *;               //来源 域名 限制,* 代表全部 / 无限制
            }

友情链接
联系方式
  • 邮箱 / E-mail:121388038@qq.com