2015-11-18 141 views
0

我加载自定义字体在标题中这样加载自定义字体:通过HTTP和HTTPS

<link rel="stylesheet" href="//example.com/stylesheets/custom-font.css"/> 

在样式表我有CSS的一个块:

@font-face { 
    font-family: 'soneregular'; 
    src: url('//example.com/fonts/webfont.eot'); 
    src: url('//example.com/fonts/webfont.eot?#iefix') format('embedded-opentype'), 
     url('//example.com/fonts/webfont.woff2') format('woff2'), 
     url('//example.com/fonts/webfont.woff') format('woff'), 
     url('//example.com/fonts/webfont.ttf') format('truetype'), 
     url('//example.com/fonts/webfont.svg#soneregular') format('svg'); 
    font-weight: normal; 
    font-style: normal; 
} 

当我有一个通过HTTP加载页面时,自定义字体加载正常,但是当通过HTTPS加载页面时,将恢复为回退字体(无衬线)并在控制台中显示这些错误:

Mixed Content: The page at 'https://example.com/ecom/myAccount/myAccount.do?forward=/' was loaded over HTTPS, but requested an insecure font 'http://example.com/fonts/webfont.woff2'. This request has been blocked; the content must be served over HTTPS. 

Mixed Content: The page at 'https://example.com/ecom/myAccount/myAccount.do?forward=/' was loaded over HTTPS, but requested an insecure font 'http://example.com/fonts/webfont.woff'. This request has been blocked; the content must be served over HTTPS. 

Mixed Content: The page at 'https://example.com/ecom/myAccount/myAccount.do?forward=/' was loaded over HTTPS, but requested an insecure font 'http://example.com/fonts/webfont.ttf'. This request has been blocked; the content must be served over HTTPS. 

我需要做些什么才能使这些自定义字体通过HTTP和HTTPS正确加载?

+0

我不擅长这个,但我认为您需要看看您的服务器如何响应字体请求,如果您的网站运行的是https,则需要确保您的资产通过https服务也可能是你的服务器决定默认为http,当没有协议指定'// address.com'时 – SidOfc

+0

哦 - 下面是一个答案,指的是特定的服务器配置,如果你至少可以共享这个名字你正在使用'apache'或'nginx'的服务器软件,例如其他人可以帮助你更好的:) – SidOfc

回答

0

尝试取消设置此文件类型的vary标头。如果您也使用其他文件类型,那么也为他们做同样的事情。

<FilesMatch "\.(woff)$"> 
    Header unset Vary 
</FilesMatch>