Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

How do I go about setting the cache control headers for specific files on my web server? I'm running a LAMP environment. I don't want to set the cache control sitewide, just for a few files. I am using CloudFront to distribute content from one of my domains. There is no S3 tie-in here. By default, content expires after 24 hours, which is fine for most of the data on the website, however, there are a few pages that I'd like to have only a 1 hour cache limit on.

share|improve this question
    
I've reread your question and replaced the tutorials with (hopefully) better ones regarding your problems; I'm sure there are significantly better ones available still, but these should be easy to find once you are more into the topic. –  Steffen Opel Jan 20 '12 at 16:12

2 Answers 2

up vote 3 down vote accepted

Amazon CloudFront (mostly) obeys the regular HTTP cache control mechanism (see RFC 2616) as documented in Amazon CloudFront Object Expiration, specifically:

You can specify a longer expiration time by using the Cache-Control, Pragma, or Expires header on the object in the origin server. [...] CloudFront does not restrict their maximum values.

The minimum expiration time you can specify is one hour. If you specify a minimum time of less than one hour, CloudFront uses one hour.

[emphasis mine]

Thus you will have to orchestrate your LAMP stack to apply the desired Cache-Control: max-age=3600 header specifically to those objects/pages, which will be picked up automatically by CloudFront during its origin fetch thereafter.

How this is done in particular depends on the tools/technologies used to serve the content of course, e.g.:

For an excellent overview about caching in general I recommend Mark Nottingham's Caching Tutorial.

share|improve this answer
    
perfect, thanks! exactly what i was looking for –  Macgyver Jan 20 '12 at 16:22

Fyi, the answer above is still correct but slightly out of date in one respect, as Cloudfront now supports a minimum TTL of 0.

Amazon Developer Guide: Expiration1

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.