【问题标题】:Cross domain issue with font-face and Apache load balancer字体和 Apache 负载均衡器的跨域问题
【发布时间】:2018-02-23 23:20:42
【问题描述】:

我在 apache 负载均衡器后面有 2 个应用程序节点,如下所示:

    ProxyRequests off
<Proxy balancer://webfarm>
    BalancerMember http://192.168.1.14:80
    BalancerMember http://192.168.2.15:80
    ProxySet lbmethod=byrequests
</Proxy>

<Location /balancer-manager>
    SetHandler balancer-manager
</Location>
ProxyPass /balancer-manager !
ProxyPass / balancer://webfarm/

通过IP单独访问实例时,字体正常加载。但是从负载均衡器访问似乎存在跨域问题:

Access to Font at 'http://192.168.1.14/fonts/open-sans/OpenSans-Bold.ttf' from origin 'http://192.168.10.10' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.10.10' is therefore not allowed access.

我尝试在两个节点和负载均衡器的 httpd.conf 上设置标头,如下所示:

AddType application/x-font-ttf           ttc ttf
AddType application/x-font-otf           otf
AddType application/font-woff            woff
AddType application/font-woff2           woff2
AddType application/vnd.ms-fontobject    eot

<FilesMatch ".(eot|ttf|otf|woff|woff2)">
  Header set Access-Control-Allow-Origin "*"
</FilesMatch>

并在所有实例上重新启动 apache。似乎不起作用。 非常感谢您的帮助。

提前致谢。

【问题讨论】:

    标签: apache cross-domain load-balancing font-face cross-domain-policy


    【解决方案1】:

    将以下内容添加到资产提供者的.htaccess中实际上解决了它,但是必须清除浏览器缓存... -.-

    AddType application/x-font-ttf           ttc ttf
    AddType application/x-font-otf           otf
    AddType application/font-woff            woff
    AddType application/font-woff2           woff2
    AddType application/vnd.ms-fontobject    eot
    
    <FilesMatch ".(eot|ttf|otf|woff|woff2)">
      Header set Access-Control-Allow-Origin "*"
    </FilesMatch>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-10
      • 1970-01-01
      相关资源
      最近更新 更多