Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My server returns the following headers:

Cache-Control:no-cache
Connection:keep-alive
Date:Thu, 07 Jul 2011 10:41:57 GMT
Expires:Thu, 01 Jan 1970 00:00:01 GMT
Last-Modified:Thu, 07 Jul 2011 08:06:32 GMT
Server:nginx/0.8.46`

I want the content I'm serving not to be cached, so I'm looking for a way to return a Last-Modified header that contains the date-time when the request was originated. Something like now()...

share|improve this question
up vote 5 down vote accepted

"I want the content I'm serving not to be cached" : You can turn off If-Modified-Since request header checking with if_modified_since off; directive. if_modified_since doc

And about Last-Modified header: You can turn it off with add_header Last-Modified "";

share|improve this answer
1  
You can't turn off headers with add_header, you can only add them. From the entry: Note that it just appends a new header entry to the output header list. So you can't use this directive to rewrite existing headers like Server. Use the headers_more module for it. – kolbyjack Jul 7 '11 at 14:16
    
I've checked it with curl -D and after adding add_header Last-MOdified ""; to my nginx.conf, Last-Modified header is no longer there in dump file. – Casual Coder Jul 7 '11 at 16:54
1  
Wow, looking at the source, Cache-Control and Last-Modified are special cased and will be set instead of having an extra entry added. It seems the wiki needs to be updated. – kolbyjack Jul 7 '11 at 18:03
    
I was wrong again, Cache-Control is special cased, but it doesn't overwrite, it just has to be added in a special way. Only Last-Modified sets the header instead of adding a new one. – kolbyjack Jul 7 '11 at 18:16
    
Good to know, could you point me to a file ? Is it in src/http/ngx_http_header_filter_module.c ? – Casual Coder Jul 7 '11 at 18:33

Other option is to make it look like a file is always modified:

add_header Last-Modified $date_gmt;
if_modified_since off;
etag off;

As for the last line, if you really want to hide a last-modified date - you must hide the ETag header too since it leaks timestamps.

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.