AWS Cloudfront行为未按预期运行

时间:2016-06-05 00:13:34

标签: amazon-web-services amazon-s3 amazon-cloudfront

我在AWS Elastic Beanstalk上有一个PHP应用程序,我在S3上创建了一个资产存储桶。我正在尝试使用行为来设置Cloudfront分发,以将资产/ *请求发送到S3,并使用默认行为向EB发送请求。该域指向Cloudfront。

所有请求都将转到EB,因为EB环境中没有资产指示,所以返回404。

我创建了2个Cloudfront源,一个用于EB,一个用于S3存储桶。这就是我的行为:

Precedence  Path Pattern  Origin                                          Protocol Policy   Fwd Query Strings
0           assets/*      S3-example-bucket                               HTTP and HTTPS    No
1           Default (*)   Custom-example.us-east-1.elasticbeanstalk.com   HTTP and HTTPS    Yes

好像这应该是非常直接的,所以我想我错过了一些基本的东西。非常感谢任何帮助。

修改

请求标题:

GET /assets/images/10waysaudiobook.png HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: wordpress_logged_in_8a27500b7747be1e4fbad7f473f238e5=snickerspixy%7C1466021823%7Cr7rE5moINjanjHEqb1TGbsSkn9F7OCZLfX69IbcnGJu%7C28fc452885f3fe6e954243abab585a188f6511cdd6eeec6fa5ec5c50b9f3d393; wp-settings-7674=m4%3Do%26m5%3Do%26m9%3Do%26m6%3Do%26editor%3Dhtml%26m10%3Do%26m0%3Do%26m3%3Do%26hidetb%3D1%26m2%3Dc%26m1%3Do%26m8%3Do%26m12%3Do%26m7%3Do%26m11%3Do%26urlbutton%3Dnone%26m13%3Do%26tml1%3D1%26imgsize%3Dfull%26align%3Dcenter%26libraryContent%3Dbrowse%26ed_size%3D569%26unfold%3D1%26wplink%3D1%26mfold%3Do%26post_dfw%3Doff%26advImgDetails%3Dshow%26posts_list_mode%3Dlist; wp-settings-time-7674=1464816549; AWSELB=1FCB85F51606EBAFF15FEADB01C8069AEDE17E2A043407E615EF1A0E1ABF24607545A45D3DC206631F7AAE4503ADA423788B5E6B5B48FAE93EE916DE068509E64F92AC10FF; PHPSESSID=cpi2su7s967phu87rlpjgneel6; wordpress_test_cookie=WP+Cookie+check
Connection: keep-alive

响应标题:

HTTP/1.1 404 Not Found
Cache-Control: no-cache, must-revalidate, max-age=0
Content-Type: text/html; charset=UTF-8
Date: Sun, 05 Jun 2016 00:54:23 GMT
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Link: <http://example.com/wp-json/>; rel="https://api.w.org/"
Pragma: no-cache
Server: Apache
Transfer-Encoding: chunked
Connection: keep-alive

1 个答案:

答案 0 :(得分:1)

响应标头表明该请求根本没有由CloudFront提供,因为存在应该存在的标头但是不存在。

CloudFront将Via:X-Cache:x-amz-cf-id:标头添加到每个响应中,有时Age:(关于缓存命中和错误)或Vary:如果您和#39;将CloudFront-Is-*-Viewer:标题重新转发到原点。

缺少这些标头表明该网站的DNS尚未指向CloudFront,并且可能仍然直接指向EB环境,或者如果更改是最近的,那么DNS条目的前TTL可能尚未过期。