Proxy_cache with variable
Jugurtha
nginx-forum at forum.nginx.org
Thu Sep 15 08:42:06 UTC 2016
Hello dream team,
I have problem when i use "proxy_cache" with a variable ! Using
"proxy_cache_purge" (call to proxy_cache) directive with a variable seems to
change that variable's value.
Tested on the last version nginx/1.11.4 (on Sles11 SP3)
I would change my name cache dynamically
The following conf is OK : (the file is purged)
########################################################################
server {
.....
location ~ /purge(/.*) {
allow 127.0.0.1;
deny all;
set $cacheSelect carto;
#echo "Zone:$cacheSelect"; //Display carto
proxy_cache_purge $cacheSelect $host$1$is_args$args;
//Return code 200 => File purged from the cache
}
...
}
########################################################################
But if i use "map" or "if" for change the cache variable, the problem
appears :
For example this URL : test.com/purge/librairies/test.js => I make sure the
file exists in the cache before
########################################################################
map $uri $select_cache {
default 'carto';
~*/tuiles/ 'tuiles';
~*/librairies/ 'librairies';
}
server {
.....
location ~ /purge(/.*) {
allow 127.0.0.1;
deny all;
set $cacheSelect carto; //carto is the default value
if ($uri ~ /librairies/(.*)$ ) {
set $cacheSelect librairies;
}
echo "Zone:$cacheSelect"; //Display librairies
echo "Zone:$select_cache"; //Display librairies
#proxy_cache_purge $select_cache $host$1$is_args$args; ==>
Return 404 (file not found in cache)
proxy_cache_purge $cacheSelect $host$1$is_args$args; ==>
Return 404 (file not found in cache)
}
...
}
########################################################################
I feel that when I use "if" or "map" in my conf it does not work anymore
Thank you for your help
Posted at Nginx Forum: https://forum.nginx.org/read.php?2,269590,269590#msg-269590
More information about the nginx
mailing list