Expires for CloudFront

Events happening in the community are now at Drupal community events on www.drupal.org.
Terko's picture

Hello!
I am trying to setup AmazonCloud front, but when I try to test with webpagetest.org I receive warning, that the files on the cdn are without no cache expires. You can see the result here:
http://www.webpagetest.org/result/101122_DBKG/1/performance_optimization...
One little snipet:

URL: http://uhaaacdn.imgcdn.net/files/imagecache/Four/6_2_0.jpg
Host: uhaaacdn.imgcdn.net
IP: 204.246.169.196
Location: Seattle, WA
Error/Status Code: 200
Start Offset: 3.227 s
Time to First Byte: 229 ms
Content Download: 132 ms
Bytes In (downloaded): 7.2 KB
Bytes Out (uploaded): 0.4 KB
Request Headers:

GET /files/imagecache/Four/6_2_0.jpg HTTP/1.1
Accept: */

Referer: http://uhaaa.com/?page=28
Accept-Language: en-us
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; PTST 2.249)
Host: uhaaacdn.imgcdn.net
Connection: Keep-Alive
Response Headers:

HTTP/1.0 200 OK
Server: nginx/0.8.49
Date: Mon, 22 Nov 2010 07:29:30 GMT
Content-Type: image/jpeg
Content-Length: 6661
Last-Modified: Mon, 22 Nov 2010 07:25:58 GMT
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Accept-Ranges: bytes
Vary: Accept-Encoding
X-Cache: Miss from cloudfront
X-Amz-Cf-Id: df1d59aff6c6a67eff086d88970e3425975acb50cb14eaedc1ed4f96f99eaa7a3e5a8b11dc4d5ee3,9f5c531d9ad1f164ffc57084a2092b890003f16cce015912a446e9f1e14a7e8433866de30960a26f
Via: 1.0 9137d054c423ede4794f3621c7d50adb.cloudfront.net:11180 (CloudFront), 1.0 e4501831a6fc90a17b3c8fe6d6f0b643.cloudfront.net:11180 (CloudFront)
Connection: keep-alive

I've put all the nessesary instructions:
# serve imagecache files directly or redirect to drupal if they do not exist
  location ~* imagecache {
    access_log off;
    expires max;
    try_files $uri @drupal;
 
add_header Cache-Control   max-age=315360000;
  }
# serve static files directly
  location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|swf|flv)$ {
    access_log        off;
    expires           max;
  }

But this don't help CloudFront to set correct expire time. The headers that I receive contain: "private, must revalidate"
http://uhaaacdn.imgcdn.net/files/imagecache/Four/11_70.jpg

GET /files/imagecache/Four/11_70.jpg HTTP/1.1
Host: uhaaacdn.imgcdn.net
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; bg; rv:1.9.2.12) Gecko/20101026 AlexaToolbar/alxf-1.54 Firefox/3.6.12 GTB7.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: bg,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive

HTTP/1.0 200 OK
Server: nginx/0.8.49
Date: Mon, 22 Nov 2010 07:49:44 GMT
Content-Type: image/jpeg
X-Powered-By: PHP/5.3.3
X-Drupal-Cache: MISS
Content-Length: 11793
Expires: Mon, 06 Dec 2010 07:49:44 GMT
Cache-Control: max-age=1209600, private, must-revalidate
Last-Modified: Mon, 22 Nov 2010 07:49:44 GMT
Etag: "158208cd9e17c7a31b9fdfb4f3b13804"
Vary: Accept-Encoding
Age: 12
X-Cache: Hit from cloudfront
X-Amz-Cf-Id: 51f2da7d0260754e3f54f1f2a72ffdabf0103dc522929aa48b4ec0f1fd6df61870af64d9da37a185
Via: 1.0 83eb7919a5076e946a3a2d59d7f4415b.cloudfront.net:11180 (CloudFront), 1.0 9cebac2d3272ba6c8b98f31159d625c7.cloudfront.net:11180 (CloudFront)
Connection: keep-alive

Please, help, because now the users revalidate their cached copies of the images every time when they browse.

Comments

Hmm.

perusio's picture

I think you need to put the header setting between double quotes:

add_header Cache-Control   "max-age=315360000";

Try it.

Thanks for your reply

Terko's picture

Thanks for your reply perusio/1
I think that I set it correctly, but still FAILED (No max-age or expires)
http://www.webpagetest.org/result/101122_NS/1/performance_optimization/c...

Well

perusio's picture

You're getting a lot of stuff from other sites, mostly counters, web bugs and such. That's bound to make loose control of your complete HTTP pipeline.

Anyway I get this for http://uhaaacdn.imgcdn.net/files/imagecache/Thumbs1/4_130.jpg:

HTTP/1.0 200 OK
Server: nginx/0.8.49
Date: Mon, 22 Nov 2010 22:42:39 GMT
Content-Type: image/jpeg
Content-Length: 13073
Last-Modified: Mon, 22 Nov 2010 16:18:00 GMT
Expires: Tue, 22 Nov 2011 22:42:39 GMT
Cache-Control: max-age=31536000
Cache-Control: max-age=315360000
Accept-Ranges: bytes
X-Cache: Miss from cloudfront
X-Amz-Cf-Id: 135081486936271d0de93fff60926eeedf73dce284d66c668a8ea274f6fb10ba33f60c81258134eb,d7e836282797e9f4cc89989bf8fa0f49bd47a7481b21d17cb8a9a0061ae1cb085a76565ec7ef05df
Via: 1.0 6a3310d18c44390fc60fcbd42b7b60e1.cloudfront.net:11180 (CloudFront), 1.0 7869b23feef4db26ff1aaac25174c284.cloudfront.net:11180 (CloudFront)
Connection: close

You're sending two Cache-Control headers. One is the one we've talked above, the other has an extra 0.

This helped! Thank you very

Terko's picture

This helped! Thank you very much! :)

Where should I made the changes?

shaydadush's picture

Hi,

Where can I do the changes you are talking about?
Plus what about Etags?

Thanks

Nginx

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: