nginx - uwsg_cache的不同配置取决于url路径
问题描述
我已经配置了 uwsgi 缓存,但我想让它在不同的位置以不同的方式工作。我的配置:
uwsgi_cache_path /tmp/nginx_cache/ levels=1:2 keys_zone=mycache:60m inactive=10m;
server {
listen *:80;
server_name thewebsite.loc;
location @uwsgi {
include uwsgi_params;
uwsgi_cache mycache;
uwsgi_cache_valid any 1h;
uwsgi_cache_key $request_uri;
uwsgi_pass unix:///var/run/app/uwsgi.sock;
uwsgi_read_timeout 120s;
}
location / {
try_files $uri @uwsgi;
}
}
比方说,我想禁用特定位置的缓存。我在块后添加/
另一个位置:
location /dynamic{
uwsgi_cache off;
try_files $uri @uwsgi;
}
但它不起作用,视图仍然被缓存。有可能或根本不应该这样工作吗?
UPD:我也尝试在location /
. 在这种情况下,它根本行不通。
解决方案
当您访问/dynamic
nginx 集uwsgi_cache off
但随后您重定向到@uwsgi
启用缓存的位置。我认为这会导致您的问题。
尝试将缓存配置移动到server
上下文:
uwsgi_cache_path /tmp/nginx_cache/ levels=1:2 keys_zone=mycache:60m inactive=10m;
server {
listen *:80;
server_name thewebsite.loc;
uwsgi_cache mycache;
uwsgi_cache_valid any 1h;
uwsgi_cache_key $request_uri;
location @uwsgi {
include uwsgi_params;
uwsgi_pass unix:///var/run/app/uwsgi.sock;
uwsgi_read_timeout 120s;
}
location / {
try_files $uri @uwsgi;
}
location /dynamic {
uwsgi_cache off;
try_files $uri @uwsgi;
}
}
注意:我没有测试这个配置,我不确定它是否会工作
推荐阅读
- php - 在雄辩的 laravel 中更新级联不起作用
- django - django save() 接受 1 个位置参数,但给出了 2 个
- resampling - .resample('M') 的问题
- mysql - group by 在查询连接中出现错误,例如 SELECT 列表不在 GROUP BY 子句中并且包含非聚合列
- r - 有什么方法可以访问 ComplexHeatmap 的移位矩阵?
- python - 在 Windows 7 中为 python2.7 安装 statsmodels 时出错
- angular - 如何在 Angular 中调试外部库?
- git - 初始化“空”目录
- nginx - nginx 使用子域和裸域重定向
- c - 程序似乎忽略了“gets()”的一个实例,并在用户未与程序交互时显示错误消息