load balancing and caching combination problem

fredericsidler nginx-forum at nginx.us
Mon Aug 31 12:57:01 MSD 2009

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


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"'

    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 = ) {
            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: http://forum.nginx.org/read.php?2,5392,5392#msg-5392

More information about the nginx mailing list