NGINX,禁用特定文件类型的特定文件夹中的缓存 [英] NGINX, Disable cache in specific folder for a specific file type

查看:56
本文介绍了NGINX,禁用特定文件类型的特定文件夹中的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,我有用于静态内容(例如产品图片等)的Windows Nginx服务器.目前,我已经设置了缓存的全局设置,但是现在我需要对其进行一些更改.

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

您会在路径中看到的是 user-hash 变量,该变量会发生变化.在此文件夹中,我有* .jpg文件,需要禁用缓存.

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';
 }

我一直希望它至少会禁用此文件夹中所有文件的缓存,并进一步禁用缓存.但是我从中得到的唯一结果是 http 403 .

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 .

我可以在文件夹 users 中使用禁用的缓存,如果可以的话还可以继续使用,但是最好的解决方案是禁用整个路径的缓存(使用 user-hash (包括em>变量),仅用于特定文件类型(* .jpg).

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).

任何想法或建议如何实现?PS:NGinx对我来说是新手,我在这项技术上花费了大约8个小时,所以很抱歉如果这是一个愚蠢的问题,但我无法在任何地方找到它或找到它.

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.

提前谢谢!

推荐答案

location ~ .*files/projectX/files/users/.*jpg$ {
          expires -1;
          add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
        }

这可以解决问题.

这篇关于NGINX,禁用特定文件类型的特定文件夹中的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆