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

There is a directory on my webserver which contains images that I don't want to be cached.

Nginx is frontend to Apache. I have caching enabled for static resources in nginx.conf:

server {
    listen 80;
        server_name www.mydomain.com mydomain.com;

        location / {
            root /home/somedomain/public_html/site;
            proxy_pass  http://backend;
            include /etc/nginx/proxy.conf;
        }

        location ~* \.(css|js)$ {
                  root /home/somedomain/public_html/site;
                  add_header  Last-Modified: $date_gmt;
                  expires 1y;
                  access_log off;
        }

        location ~* \.(jpg|jpeg|gif|png|ico|bmp|swf)$ {
                  root /home/somedomain/public_html/site;
                  expires max;
                  access_log off;
        }

        location ~ \.php { 
            proxy_pass  http://backend;
            include /etc/nginx/proxy.conf;
        }


}

I tried to add to the end:

location /home/somedomain/public_html/site/dontcache/ \.png {
                 root /home/somedomain/public_html/site/dontcache;
                 expires off;
}

Also tried expires -1; and expires 1m; but all of that doesnt seem to work.

I know it is simple but I just can't get why it doesnt work for me.

share|improve this question
add comment

2 Answers

location ^~ /home/somedomain/public_html/site/dontcache/ {
  root /home/somedomain/public_html/site/dontcache;
  expires epoch;
}

The order of matching for location directives is described here

share|improve this answer
add comment

Try this:

location /home/somedomain/public_html/site/dontcache/ \.png {
                 root /home/somedomain/public_html/site/dontcache;
                 proxy_no_cache 1;
}

Also, look here: http://sysoev.ru/nginx/docs/http/ngx_http_proxy_module.html#proxy_no_cache

share|improve this answer
    
Wrong answer. The original configuration does not use proxy_cache at all. –  Alexander Azarov Aug 17 '11 at 16:09
    
My bad. I was messed by "I have caching enabled for static resources in nginx.conf:" –  HUB Aug 17 '11 at 18:52
add comment

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.