﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
1142	Location vars fails when use map variable in try_files	Edu Herraiz		"Trying to use a map variable inside a try_files this way:

{{{
map $http_accept $webp_prefix { 
    default   """";
    ""~*webp*""  ""/webp"";
}    

...
    
location ~* ""^/(..)(..)(.+)?$"" {
  root        /data/result_storage/v2;
  expires     1M;
  try_files $webp_prefix/$1/$2$uri =404;
}
}}}

We found the vars $1 and $2 are not correctly recollected:

{{{
nginx_1    | 2016/11/23 17:14:20 [debug] 12#12: *1 http map started
nginx_1    | 2016/11/23 17:14:20 [debug] 12#12: *1 http script var: ""text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8""
nginx_1    | 2016/11/23 17:14:20 [debug] 12#12: *1 http map: ""text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"" ""/webp""
nginx_1    | 2016/11/23 17:14:20 [debug] 12#12: *1 http script var: ""/webp""
nginx_1    | 2016/11/23 17:14:20 [debug] 12#12: *1 http script copy: ""/""
nginx_1    | 2016/11/23 17:14:20 [debug] 12#12: *1 http script capture: """"
nginx_1    | 2016/11/23 17:14:20 [debug] 12#12: *1 http script copy: ""/""
nginx_1    | 2016/11/23 17:14:20 [debug] 12#12: *1 http script capture: """"
nginx_1    | 2016/11/23 17:14:20 [debug] 12#12: *1 http script var: ""/HV5vyg-_H07z7o-g2DaGj5nrkeA=/700x200/www.apsl.net/static/apslweb/img/apsl.png""
nginx_1    | 2016/11/23 17:14:20 [debug] 12#12: *1 trying to use file: ""/webp///HV5vyg-_H07z7o-g2DaGj5nrkeA=/700x200/www.apsl.net/static/apslweb/img/apsl.png"" ""/data/result_storage/v2/webp///HV5vyg-_H07z7o-g2DaGj5nrkeA=/700x200/www.apsl.net/static/apslweb/img/apsl.png""
}}}

In the case we not use the map in the try_files:
{{{
map $http_accept $webp_prefix { 
    default   """";
    ""~*webp*""  ""/webp"";
}    

...
    
location ~* ""^/(..)(..)(.+)?$"" {
  root        /data/result_storage/v2;
  expires     1M;
  try_files /webp/$1/$2$uri =404;
}
}}}

Works properly:
{{{
nginx_1    | 2016/11/23 17:18:21 [debug] 11#11: *1 http script copy: ""/webp/""
nginx_1    | 2016/11/23 17:18:21 [debug] 11#11: *1 http script capture: ""HV""
nginx_1    | 2016/11/23 17:18:21 [debug] 11#11: *1 http script copy: ""/""
nginx_1    | 2016/11/23 17:18:21 [debug] 11#11: *1 http script capture: ""5v""
nginx_1    | 2016/11/23 17:18:21 [debug] 11#11: *1 http script var: ""/HV5vyg-_H07z7o-g2DaGj5nrkeA=/700x200/www.apsl.net/static/apslweb/img/apsl.png""
nginx_1    | 2016/11/23 17:18:21 [debug] 11#11: *1 trying to use file: ""/webp/HV/5v/HV5vyg-_H07z7o-g2DaGj5nrkeA=/700x200/www.apsl.net/static/apslweb/img/apsl.png""
}}}

Note the URI we are trying to GET is:
/HV5vyg-_H07z7o-g2DaGj5nrkeA=/700x200/www.apsl.net/static/apslweb/img/apsl.png

We found a old examples using this configuration, but we can make this to work.
Are we missing something?"	defect	closed	major		other	1.11.x	duplicate	try_files map		Linux fae1582a4c7a 4.4.1-040401-generic #201601311534 SMP Sun Jan 31 20:36:43 UTC 2016 x86_64 GNU/Linux	"nginx version: nginx/1.11.5
built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.1t  3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed'
"
