I have -unfortunately Windows- Nginx server that I use for a static content (like product photos and so on). Currently I have had a global setting for caching, but now I need to change it little.
I have a folder which path looks something like this:
E:\xampp\srv\project-files\projectX\files\users\user-hash\visualisator\views
As you can see in the path is the user-hash variable which changes. And in this folder I have *.jpg files that need to have cache disabled.
I have already tried something like this (located on top of the other (global) location settings):
location ~ /users/ {
alias "E:/xampp/srv/project-files/projectX/files/users";
expires -1;
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
}
And I have been hoping that it will at least disable cache for all the files in this folder and further. But the only result I am getting from this is http 403
.
I can live with disabled cache from the folder users
and further if it will works, but the best solution would be to disable cache for the whole path (with user-hash variable included) and just for a specific file type (*.jpg).
Any idea or recommendation how to achieve this? PS: NGinx is new for me, I have spent like 8 hours tops with this technology, so sorry if it is stupid question, but I can't possibly figure it out or find it anywhere.
Thank you in advance!
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.
proxy_cache_valid. Sets caching time for different response codes. If only caching time is specified then only 200, 301, and 302 responses are cached.
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.
location ~ .*files/projectX/files/users/.*jpg$ {
expires -1;
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
}
This does the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With