Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx, turn off cache for a specific file

Tags:

caching

nginx

location /static {
    alias /home/ubuntu/Documents/zibann/momsite/momsite/static; # your Django project's static files - amend as required
    if ($uri ~* ".*config.js") {
       expires off;
    }

    if ($uri ~* ".*\.(js|css|png|jpg|jpeg|gif|swf|svg)" ) {
       access_log off;
       expires 365d;
       add_header Cache-Control public;
    }

}

Hoping config.js would not get cached, but it does.
How can I exclude one file from being cached?

like image 786
eugene Avatar asked Apr 06 '15 06:04

eugene


People also ask

Does nginx cache static files?

Cache both static and dynamic content from your proxied web and application servers, to speed delivery to clients and reduce the load on the servers.

What is Proxy_cache in nginx?

Nginx caches the responses in the disk, proxy_cache_path specifies the path where the responses are to be stored. proxy_cache defines the shared memory zone used for storing the cache keys and other metadata. proxy_cache_key defines the caching key.

Does nginx cache in memory?

NGINX and NGINX Plus utilize a hybrid disk‑and‑memory cache. Whether the cache is on disk, in SSD, or elsewhere, the operating system page cache brings a cached item into main memory when it's requested. The cached content that was requested least recently is swapped out when memory is required for other purposes.


1 Answers

Make a separate location block for config.js above the others.

location ~ config\.js {
    alias xyz;
    expires off;
}

location static etc
like image 64
Dayo Avatar answered Sep 27 '22 20:09

Dayo