uwsg_cache 的不同配置取决于 url 路径
Different configuration of uwsg_cache depends on url path
我配置了 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;
<b>uwsgi_cache mycache;
uwsgi_cache_valid any 1h;
uwsgi_cache_key $request_uri;</b>
location @uwsgi {
include uwsgi_params;
uwsgi_pass unix:///var/run/app/uwsgi.sock;
uwsgi_read_timeout 120s;
}
location / {
try_files $uri @uwsgi;
}
<b>location /dynamic {
uwsgi_cache off;
try_files $uri @uwsgi;
}</b>
}
CAUTION: I did not test this config, I'm not sure if it will work
我配置了 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;
<b>uwsgi_cache mycache;
uwsgi_cache_valid any 1h;
uwsgi_cache_key $request_uri;</b>
location @uwsgi {
include uwsgi_params;
uwsgi_pass unix:///var/run/app/uwsgi.sock;
uwsgi_read_timeout 120s;
}
location / {
try_files $uri @uwsgi;
}
<b>location /dynamic {
uwsgi_cache off;
try_files $uri @uwsgi;
}</b>
}
CAUTION: I did not test this config, I'm not sure if it will work