# Load balancing and caching combination problem

**URL:** <https://www.ruby-forum.com/t/load-balancing-and-caching-combination-problem/174676>\
**Category:** NGINX\
**Created:** [August 31, 2009, 11:05am UTC](https://www.ruby-forum.com/t/load-balancing-and-caching-combination-problem/174676 "2009-08-31T11:05:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredericsidler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a6a055/32.png) [@fredericsidler](https://www.ruby-forum.com/u/fredericsidler)\
**Post date:** [August 31, 2009, 11:05am UTC](https://www.ruby-forum.com/t/load-balancing-and-caching-combination-problem/174676/1 "2009-08-31T11:05:25Z")

</div>

I just installed nginx 0.8.11 in order to use the $upstream\_cache\_status  
variable.

I can see now in the logs that my URLs (ics feed URLs) are cached and  
retrieved from the cache (MISS, HIT, EXPIRED) based on my caching  
parameters.

But, it only works when  
proxy\_ignore\_headers Cache-Control;  
proxy\_ignore\_headers Expires;

are used and left uncommented. I have read in the forums that this  
shouldn’t be use in production. So what should I do next to be able to  
comment these parameters and get the result I’m expected.

I tried to set the Expires header by using set\_proxy\_header, but no  
headers are added to my file. Here is my configuration file and the  
headers of one the ICS file

nginx.conf

user www-data;  
worker\_processes 4;

error\_log /var/log/nginx/error.log;  
pid /var/run/nginx.pid;

events {  
worker\_connections 4096;  
}

http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;

```
log_format fbcal '$remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent '
                 '"$http_referer" "$http_user_agent"'
                 '"$upstream_cache_status"';

access_log /var/log/nginx/access.log fbcal;

sendfile on;

keepalive_timeout 30;
tcp_nodelay on;

include /etc/nginx/app-servers.include;

proxy_cache_path /var/www/fbcaldotcom/cache levels=1:2 

```

keys\_zone=one:10m;  
proxy\_temp\_path /temp/cache;

```
server {
    listen 80;

    if ( $remote_addr = 127.0.0.1 ) {
        rewrite ^(.*)$ /500.html last;
        return 302;

    }

    location / {
        proxy_pass http://backend;

        proxy_cache one;
        proxy_cache_key backend$request_uri;
        proxy_cache_valid 200 3h;
        proxy_cache_use_stale error timeout invalid_header;

```

# proxy\_ignore\_headers Cache-Control;

# proxy\_ignore\_headers Expires;

```
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For 

```

$proxy\_add\_x\_forwarded\_for;

```
        error_page 500 501 = /500.html;
        error_page 502 503 504 = /502.html;
    }

    location /500.html {
            root /var/www/nginx-default;
    }

    location /502.html {
            root /var/www/nginx-default;
    }

}

```

}

curl -I

HTTP/1.1 200 OK  
Server: nginx/0.8.11  
Date: Mon, 31 Aug 2009 08:41:57 GMT  
Content-Type: text/calendar; charset=utf-8  
Connection: keep-alive  
X-Powered-By: PHP/5.2.4-2ubuntu5.7  
Content-Disposition: attachment; filename=“fbCal-Events.ics”  
Cache-Control: max-age=10  
Content-Length: 80450

Posted at Nginx Forum:

> **[load balancing and caching combination problem](https://forum.nginx.org/read.php?2,5392,5392#msg-5392)**
>
> I just installed nginx 0.8.11 in order to use the $upstream\_cache\_status variable. I can see now in the logs that my URLs (ics feed URLs) are cached and retrieved from the cache (MISS, HIT, EXPIRED) based on my caching parameters. But, it only works...

---

<div class="post-metadata">

**Author:** ![fredericsidler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a6a055/32.png) [@fredericsidler](https://www.ruby-forum.com/u/fredericsidler)\
**Post date:** [August 31, 2009, 12:28pm UTC](https://www.ruby-forum.com/t/load-balancing-and-caching-combination-problem/174676/2 "2009-08-31T12:28:00Z")

</div>

Hello!

On Mon, Aug 31, 2009 at 04:57:01AM -0400, fredericsidler wrote:

> I just installed nginx 0.8.11 in order to use the $upstream\_cache\_status variable.
> 
> I can see now in the logs that my URLs (ics feed URLs) are cached and retrieved from the cache (MISS, HIT, EXPIRED) based on my caching parameters.
> 
> But, it only works when  
> proxy\_ignore\_headers Cache-Control;  
> proxy\_ignore\_headers Expires;
> 
> are used and left uncommented. I have read in the forums that this shouldn’t be use in production. So what should I do next to be able to comment these parameters and get the result I’m expected.

Directive proxy\_ignore\_headers instruct nginx to _ignore_ headers  
in question got from upstream. And as you have Cache-Control  
returned by your upstream - nginx honors it unless  
proxy\_ignore\_headers specified. There is nothing wrong here.

Best solution would be to fix upstream server to return cache-related  
headers you want. If you can’t do that for some reason - the only  
way is to use proxy\_ignore\_headers.

> I tried to set the Expires header by using set\_proxy\_header, but no headers are added to my file. Here is my configuration file and the headers of one the ICS file

Directive proxy\_set\_header sets headers sent to upstream, it’s  
completely unrelated. There is no way to alter upstream response  
before caching it.

Maxim D.

---

<div class="post-metadata">

**Author:** ![fredericsidler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a6a055/32.png) [@fredericsidler](https://www.ruby-forum.com/u/fredericsidler)\
**Post date:** [September 1, 2009, 7:50am UTC](https://www.ruby-forum.com/t/load-balancing-and-caching-combination-problem/174676/3 "2009-09-01T07:50:15Z")

</div>

Hello Maxim,

I found out where the problem was!  
Cache-Control: max-age=10  
where 10 are 10 seconds.

Setting the Cache-Control to 3 hours  
Cache-Control: max-age=10800  
works as expected.

Posted at Nginx Forum:

> **[Re: load balancing and caching combination problem](https://forum.nginx.org/read.php?2,5392,5400#msg-5400)**
>
> I just installed nginx 0.8.11 in order to use the $upstream\_cache\_status variable. I can see now in the logs that my URLs (ics feed URLs) are cached and retrieved from the cache (MISS, HIT, EXPIRED) based on my caching parameters. But, it only works...
