Opened 8 years ago

Closed 8 years ago

#1044 closed defect (duplicate)

map break regexp numbered references

Reported by: higuita Owned by:
Priority: minor Milestone:
Component: other Version: 1.10.x
Keywords: Cc:
uname -a: Linux 154314e1156e 4.7.0-040700-generic #201608021801 SMP Tue Aug 2 22:03:09 UTC 2016 x86_64 Linux
nginx -V: nginx version: nginx/1.10.1
built with OpenSSL 1.0.2h 3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/var/lib/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx/ --lock-path=/run/nginx/nginx.lock --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-ipv6


when creating a rewrite like this:

rewrite ^/site/([^/]*)/[^-]*-(.*)$   /site/${site}/$1/$2 last;

where the $site is set by a map, i get /site/mysite as result from a request to


If i remove the ${site}, i get /site/small/633.jpg

If i replaced the numbered references by named references:

rewrite ^/site/(?<first>[^/]*)/[^-]*-(?<second>.*)$   /site/${site}/${first}/${second} last;

everything works fine.

As the map documentation reports, map is evaluated the moment the variable is used and it is resetting the numbered references.

So either keep any numbered references when calling map, or change the documentation about this pitfall and point the user to named references instead.

right now only expert users, that understand how nginx work internally may know about this and normal users generate broken configs and run away from map because they can not understand it... most will use many "if" as workaround, generating other problems later on

Change History (2)

comment:1 by higuita, 8 years ago

of course, this numbered references being reset problem might show up in other places too, so maybe always recommend named references is a good idea

comment:2 by Maxim Dounin, 8 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #564.

Note: See TracTickets for help on using tickets.