3

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.

moogeek
  • 165
  • 1
  • 3
  • 6

2 Answers2

4
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

Alexander Azarov
  • 3,550
  • 21
  • 19
  • On wordpress websites, can I enable this for wp-admin areas? `location ^~ /wordpress/wp-admin { expires epoch; proxy_no_cache 1; }` – PKHunter Feb 14 '17 at 10:49
1

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

HUB
  • 6,630
  • 3
  • 23
  • 22