I'm trying to cache whole site with CloudFront with ELB and EC2 as a backend. Response header for url I always get miss from X-Cache :
Cache-Control:max-age=0
Cache-Control:public
Connection:keep-alive
Content-Encoding:gzip
Content-Length:12501
Content-Type:text/html
Date:Tue, 08 Sep 2015 07:16:56 GMT
Expires:Tue, 08 Sep 2015 07:16:56 GMT
Server:nginx
Vary:Accept-Encoding
Via:1.1 e5f2e8167f4cb891927a3b8ab905bfaf.cloudfront.net (CloudFront)
X-Cache:Miss from cloudfront
The config webserver (Nginx) :
server {
listen 80;
server_name somedomain.com www.somedomain.com;
access_log /var/log/nginx/access.log;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header $Set_Cookie;
location ~ / {
add_header Cache-Control "public";
add_header X-Cache-Status $upstream_cache_status;
expires 0;
proxy_pass http://my_stream;
}
}
Object caching for default (*) behaviour at cloudfront I'm using costumize with :
Minimum TTL 200
Maximum TTL 400
Default TTL 320
and whitelist for headers is :
Host
CloudFront-Is-Desktop-Viewer
CloudFront-Is-Mobile-Viewer
CloudFront-Is-Tablet-Viewer
If I'm pointing directly file eg: http://somedomain.com/a_file.php , I'll get X-Cache : Hit for next refresh. But if only http://somedomain I only get X-Cache : Miss from cloudfront
Is there something miss with my config ?
The CloudFront min/max/default ttls don't override what your origin server appears to be returning:
Cache-Control: max-age=0
This overrides all the defaults.
To change the cache duration for an individual object, you can configure your origin to add a
Cache-Control max-age
orCache-Control s-maxage
directive, or anExpires
header field to the object.http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.