AWS cloudfront - 為什麼我的資產在頁面速度測試中出現兩次?

AWS cloudfront - 為什麼我的資產在頁面速度測試中出現兩次?

這是一個例子:http://tools.pingdom.com/fpt/#!/cp​​0wwy/http://www.shearcomfort.com/Car-Seat-Covers_CDN.asp

選擇任意圖像,然後2014_subaru_outback_mini.jpg您可以看到它出現兩次:一次來自雲端,大小為 0 字節,第二次來自實際域shearcomfort.com

誰能解釋一下這裡發生了什麼以及如何使所有資產僅來自雲端前端而不是來自主域?

答案1

您的 CDN URL 返回 301 重定向。

curl -I http://d3cerlni7xmxaw.cloudfront.net/images/stars/images/2starrating.gif

HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Content-Length: 186
Connection: keep-alive
Location: http://www.shearcomfort.com/images/stars/images/2starrating.gif
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Tue, 20 May 2014 17:43:02 GMT
X-Cache: Miss from cloudfront
Via: 1.1 45f9deebd67d2bd40b8384feda6e6e32.cloudfront.net (CloudFront)
X-Amz-Cf-Id: dcbTEOwj48JfPD8YrvKrk4m2-OCkCAAABdqnwGxBOfRkmdLLpl7ErQ==

我敢打賭您將 CloudFront 發行版指向而shearcomfort.com不是www.shearcomfort.com.您會看到該網域上的 301 URL 為 www 版本。

答案2

如果您使用的是僅 https 的站點,並且 301 將 http 訪客重新導向到 https(因此也是 cloudfront),則也可能會發生 301 永久移動。

在cloudfront“來源協定策略”中的origin下方有一個設置,請確保將其設置為“匹配檢視器”,以便cloudfront從您的來源伺服器請求https版本,而不是http(預設)。

相關內容