# Max-age/header problems with nginx

**URL:** <https://www.ruby-forum.com/t/max-age-header-problems-with-nginx/195192>\
**Category:** Rails\
**Created:** [September 18, 2010, 11:32pm UTC](https://www.ruby-forum.com/t/max-age-header-problems-with-nginx/195192 "2010-09-18T23:32:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [September 18, 2010, 11:32pm UTC](https://www.ruby-forum.com/t/max-age-header-problems-with-nginx/195192/1 "2010-09-18T23:32:16Z")

</div>

0 down vote favorite

I notice that in my production enviornment (where I have memcached  
implemented) in see a cache-control - max-age header in firebug,  
anytime I am looking at an index page (posts for example).

Cache-Control max-age=315360000

In my dev environment that header looks like following.

Cache-Contro private, max-age=0, must-revalidate

As far as I know I have not done anything special with my nginx.conf  
file to specify max age for regular content, I do have expires-max set  
for css, jpg etc. here is my nginx.conf file…

[http://pastie.org/1167080](http://pastie.org/1167080)

So why is this cache-control is being set? How can I control this  
cache-control, because the side effect of this is kinda bad. This is  
what happens.

1 - User request all\_posts listing and get a list of 10 pages  
(paginated)

2 - User view page 1, 2 3 and the respective caches are created.

3 - User goes back to page 1 and firefox does not even make a request  
to the server. Normally I would expect it would reqeust and hit the  
cache created in step #2.

The other issue is that if a new post has been created and now the  
cache is refreshed and it should be at the top of page 1, the user  
does not get to see it…because the browser isn’t hitting the server.

Please help!

Thanks

Update :

I tried setting expires\_now in my index action. NO difference the max-  
age is still the same large value.

---

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [September 18, 2010, 11:59pm UTC](https://www.ruby-forum.com/t/max-age-header-problems-with-nginx/195192/2 "2010-09-18T23:59:46Z")

</div>

The Sat, 18 Sep 2010 14:30:57 -0700 (PDT),  
badnaam [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Cache-Contro private, max-age=0, must-revalidate
> 
> As far as I know I have not done anything special with my nginx.conf  
> file to specify max age for regular content, I do have expires-max set  
> for css, jpg etc. here is my nginx.conf file…
> 
> [http://pastie.org/1167080](http://pastie.org/1167080)

Look more closely at your regex in your pastie :

location ~\* ^.+.(jpg|jpeg|gif|png|css|js|swf)?([0-9]+)?$ {  
expires max;  
passenger\_enabled on;  
}

An expression is optional when followed by ‘?’

So your regex matches anything with at least 2 characters (.+ matches  
one or more characters, and the following ‘.’ matches one character,  
the remaining is optional)

Happy regex hacking,

Lionel

---

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [September 19, 2010, 12:05am UTC](https://www.ruby-forum.com/t/max-age-header-problems-with-nginx/195192/3 "2010-09-19T00:05:02Z")

</div>

Hmm…not a regex expert at all. The one above obviously was borrowed.

So how can I limit it to only asset files but not html or ajax  
content? I understand this is a rails forum…but I am hoping someone  
must have done this before.

Good catch!

On Sep 18, 2:58 pm, Lionel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![badnaam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e36b37/32.png) [@badnaam](https://www.ruby-forum.com/u/badnaam)\
**Post date:** [September 20, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/max-age-header-problems-with-nginx/195192/4 "2010-09-20T21:21:26Z")

</div>

badnaam wrote:

> Hmm…not a regex expert at all. The one above obviously was borrowed.
> 
> So how can I limit it to only asset files but not html or ajax  
> content? I understand this is a rails forum…but I am hoping someone  
> must have done this before.

> **[Rubular](https://rubular.com/)**
>
> Ruby-based regular expression editor/tester

> Good catch!

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
