Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I try to serve an index page with nginx, using it's proxy_cache functionality. Everything works fine regards ordinary browsing with broswers. But when I try to get page's content with curl or when I use siege on the index page, nginx begins to work not as I have expected. It passes the request further to apache when page's cache is out of date.

I can't understand, why nginx doesn't create a new cache of the index page when it was requested with curl or siege?

Here is a part of nginx.conf:

    proxy_cache_path /var/cache/nginx levels=2 keys_zone=pagecache:100m inactive=1m max_size=500m;

    location = / {
            set $o_uri $request_uri;

            if ( $http_cookie !~ "mytestcookie" ) {
                    rewrite ^ /ng_cache last;
            }

            proxy_pass http://127.0.0.1:88;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /ng_cache {
            internal;

            root /home/$host/www;

            proxy_cache             pagecache;
            proxy_cache_valid       200 301 302 304 1m;
            proxy_hide_header       "Set-Cookie";
            proxy_ignore_headers    "Cache-Control" "Expires";

            proxy_pass              http://127.0.0.1:88$o_uri;
            proxy_set_header        Host             $host;
            proxy_set_header        X-Real-IP        $remote_addr;
    }
share|improve this question

1 Answer 1

up vote 2 down vote accepted

The proxy_hide_header Set-Cookie line in your config suggests that your backend returns Set-Cookie header, which will prevent nginx from caching such a response by default. You likely want to add Set-Cookie to proxy_ignore_headers in your config:

proxy_ignore_headers    Cache-Control Expires Set-Cookie;

See docs for details.

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.