I'm a front desk engineer and I don't know much about the server.
I would like to cache the image file saved in S3 using Wordpress in EC2 of AWS from CloudFront, but I am having trouble setting Expires for browser cache.
Please let me know if you have any solutions or other best practices.
■ Configuration
Route 53 → CloudFront → S3 (image only)
Route 53 → CloudFront → EC2 nginx 1.8.1 (Other)
We are adding Expires and Cache-Control from S3 metadata, specifying "cdn.test.com" as the alias of Route 53's A record, and going to get images from CloudFront to S3.
However, "cdn.test.com" does not add Expires, and when you connect directly to the S3 link, Expires is added.
■ Symptoms
$curl --head https://cdn.test.com/wp-content/uploads/2017/03/test.jpg
HTTP/1.1200 OK
Content-Type: image/jpeg
Content-Length—394513
Connection:keep-alive
Date:Tue, 14 Mar 2017 02:47:04 GMT
Last-Modified: Sun, 12 Mar 2017 17:29:54 GMT
ETag: "52a8ee6dfdfaf5e603da9bb8b3f56fd5"
Accept-Ranges:bytes
Server: AmazonS3
Age—2
X-Cache:Hit from cloudfront
Via: 1.1 c1f0e44a53c3128a4cc0e658159f64e0.cloudfront.net (CloudFront)
X-Amz-Cf-Id: Rc8zI-O2PGgAaDL84eiv3BF4l2bWsMbWEhXkdXopKQuVpxcly4JElg==
$curl --head http://s3-ap-northeast-1.amazonaws.com/testbucket/wp-content/uploads/2017/03/test.jpg
HTTP/1.1200 OK
x-amz-id-2: PAflQhja0j1wdU/8iBZBPjZd8c0hCPYWxH1Gk7hYybDTl+iaf7NfO0+SYuN5dNckJpSWgSbPT44=
x-amz-request-id —AB629EFFA150675B
Date:Tue, 14 Mar 2017 02:47:53 GMT
Last-Modified:Tue, 14 Mar 2017 01:24:28 GMT
ETag: "a83f5aa4cd37b92e41d41bc2406fa8e"
Cache-Control: max-age = 0
Expires: Mon, 20 Mar 2017 20:18:54 GMT
Accept-Ranges:bytes
Content-Type: image/jpeg
Content-Length—116462
Server: AmazonS3
There are two ways to control cache time in your browser while caching in CloudFront:(However, both of them need to properly set the TTL on the CloudFront side)
More information can be found in the following documents:
As it says, "Cache-Control or Expires header," there seems to be no definition of what happens when both are written.
© 2024 OneMinuteCode. All rights reserved.