Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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_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 {

            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    $o_uri;
            proxy_set_header        Host             $host;
            proxy_set_header        X-Real-IP        $remote_addr;
share|improve this question
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


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.