# Order of HTTP headers change cache behaviour

**URL:** <https://www.ruby-forum.com/t/order-of-http-headers-change-cache-behaviour/217146>\
**Category:** NGINX\
**Created:** [February 22, 2012, 5:06pm UTC](https://www.ruby-forum.com/t/order-of-http-headers-change-cache-behaviour/217146 "2012-02-22T17:06:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 22, 2012, 5:06pm UTC](https://www.ruby-forum.com/t/order-of-http-headers-change-cache-behaviour/217146/1 "2012-02-22T17:06:25Z")

</div>

Hello.

Looking at my log I’ve noticed that some pages were not cached. After a  
bit of debugging I’ve noticed that the order in which the HTTP header  
are returned from Apache change how NGINX this save the page in the  
cache

So a page with this code is _NOT_ cached

\<?php header('Content-Type: text/html; charset=UTF-8'); header('Last-Modified: Wed, 22 Feb 2012 14:44:11 GMT'); header('Expires: Wed, 11 Jan 1984 05:00:00 GMT'); header("X-Accel-Expires: 600"); header('Cache-Control: no-cache, must-revalidate, max-age=0'); header('Pragma: no-cache'); Echo "Hello World !"; ?\>

if I comment/delete the line header(‘Expires: Wed, 11 Jan 1984 05:00:00  
GMT’); the page is cached.

Even if I move header(“X-Accel-Expires: 600”) before header(‘Expires:  
Wed, 11 Jan 1984 05:00:00 GMT’); the page is cached  
Same thing happen for the header Cache-Control. If is before  
X-Accel-Expires the page is not cached if is after it is !

The conf for NGINX is very standard and proxy\_cache\_valid is not  
specified.

Is this correct ? Where am I wrong ?

Thanks

–  
Simone

---

<div class="post-metadata">

**Author:** ![hpatoio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a9adbd/32.png) [@hpatoio](https://www.ruby-forum.com/u/hpatoio)\
**Post date:** [February 22, 2012, 5:28pm UTC](https://www.ruby-forum.com/t/order-of-http-headers-change-cache-behaviour/217146/2 "2012-02-22T17:28:46Z")

</div>

Hello!

On Wed, Feb 22, 2012 at 05:05:32PM +0100, Simone F. wrote:

> header(‘Expires: Wed, 11 Jan 1984 05:00:00 GMT’);  
> Even if I move header(“X-Accel-Expires: 600”) before header(‘Expires: Wed, 11  
> Jan 1984 05:00:00 GMT’); the page is cached  
> Same thing happen for the header Cache-Control. If is before X-Accel-Expires the  
> page is not cached if is after it is !
> 
> The conf for NGINX is very standard and proxy\_cache\_valid is not specified.
> 
> Is this correct ? Where am I wrong ?

This probably should be counted as a bug (or at least  
misfeature).

Here are what happens: if the Expires header comes first, it  
disables caching due to being set to date in the past. The  
X-Accel-Expires header which comes later can’t re-enable caching.

On the other hand, if X-Accel-Expires comes first, it will set  
cache expiration time. The Expires and Cache-Control headers  
later will be just ignored as cache expiration time is already  
set.

As a workaround you may want to always sent X-Accel-Expires first,  
or explicitly ignore other headers with proxy\_ignore\_headers.

Maxim D.

---

<div class="post-metadata">

**Author:** ![hpatoio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a9adbd/32.png) [@hpatoio](https://www.ruby-forum.com/u/hpatoio)\
**Post date:** [February 22, 2012, 5:39pm UTC](https://www.ruby-forum.com/t/order-of-http-headers-change-cache-behaviour/217146/3 "2012-02-22T17:39:57Z")

</div>

On 02/22/2012 05:28 PM, Maxim D. wrote:

> This probably should be counted as a bug (or at least misfeature).

Ciao, do you think you will fix/change this behaviour ?  
Just to know if and how change my configurations

thanks

–  
Simone

---

<div class="post-metadata">

**Author:** ![hpatoio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a9adbd/32.png) [@hpatoio](https://www.ruby-forum.com/u/hpatoio)\
**Post date:** [February 22, 2012, 6:04pm UTC](https://www.ruby-forum.com/t/order-of-http-headers-change-cache-behaviour/217146/4 "2012-02-22T18:04:48Z")

</div>

Hello!

On Wed, Feb 22, 2012 at 05:39:22PM +0100, Simone F. wrote:

> On 02/22/2012 05:28 PM, Maxim D. wrote:
> 
> > This probably should be counted as a bug (or at least misfeature).
> 
> Ciao, do you think you will fix/change this behaviour ?  
> Just to know if and how change my configurations

Eventually this will be fixed, but there are no immediate plans  
to and it’s relatively low priority.

Maxim D.
