Welcome! Log In Create A New Profile

Advanced

proxy_cache and variable

October 29, 2015 01:41AM
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?
Subject Author Posted

proxy_cache and variable

trungaczne October 29, 2015 01:41AM

Re: proxy_cache and variable

Ekaterina Kukushkina October 29, 2015 02:56AM

Re: proxy_cache and variable

trungaczne October 29, 2015 03:26AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 75
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready