proxy_cache and variable
trungaczne
nginx-forum at nginx.us
Thu Oct 29 05:41:46 UTC 2015
Using "proxy_cache" directive with a variable seems to change that
variable's value.
Tested against a fresh install of nginx 1.9.6 (default configure parameters)
on 2 different Ubuntu:14.04 hosts. DigitalOcean droplets.
The following configuration works as expected: It returns 0/1/2 depending on
the mimetype returned by the upstream. The returned header is always
correct.
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
map $upstream_http_content_type $should_not_cache {
default 1;
"~image/" 2;
"~css" 0;
}
add_header X-Should-Not-Cache $should_not_cache;
server {
listen 80;
server_name myupstream.com;
location / {
proxy_pass http://<upstreamip>;
proxy_set_header Host $host;
}
}
}
This on the other hand always return the default value of the "map"
directive (X-Should-Not-Cache always return 1 regardless of whether it's
css/image/etc):
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
map $upstream_http_content_type $should_not_cache {
default 1;
"~image/" 2;
"~css" 0;
}
proxy_cache_path /tmp/low levels=1:2 keys_zone=0:1m inactive=1m
max_size=1g;
proxy_cache_path /tmp/medium levels=1:2 keys_zone=1:1m inactive=1m
max_size=1g;
proxy_cache_path /tmp/high levels=1:2 keys_zone=2:10m inactive=10m
max_size=1g;
proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args";
proxy_cache_methods GET HEAD;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_cache $should_not_cache;
add_header X-Should-Not-Cache $should_not_cache;
server {
listen 80;
server_name myupstream.com;
location / {
proxy_pass http://<upstreamip>;
proxy_set_header Host $host;
}
}
}
(basically I'm trying to have different cache zones for different mime types
with different time parameters)
Also, in the second config, commenting out the "proxy_cache" directive makes
the header correct again.
Can anybody explain this behavior?
Posted at Nginx Forum: https://forum.nginx.org/read.php?2,262527,262527#msg-262527
More information about the nginx
mailing list