Opened 10 years ago

Closed 8 years ago

Last modified 8 years ago

#663 closed enhancement (fixed)

Variable interpolation inside Map directive

Reported by: Ronaldo Pontes Owned by:
Priority: minor Milestone:
Component: nginx-module Version: 1.7.x
Keywords: map, interpolation Cc:
uname -a: Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.7.7
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx/nginx-1.7.7 --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/local/nginx/nginx-1.7.7/sbin/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_perl_module --add-module=/tmp/nginx_naxsi --add-module=/tmp/nginx_auth_request --add-module=/tmp/nginx_headers_more --with-http_stub_status_module --add-module=/tmp/nginx_echo --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module


I am trying to map a variable inside the http directive in Nginx.

When left alone, the variable alone gets expanded, if I add anything else to the string the expansion stops working.

http {

map $host $foo {

#default "$host"; # - this works fine and returns 'localhost'
default "This is my host: $host"; # - THIS DOESN'T WORK


server {

location / {

echo $foo;




Change History (7)

comment:1 by Maxim Dounin, 10 years ago

Status: newaccepted
Type: defectenhancement

This is expected behaviour. Only a single variable can be used as a resulting value, see

The resulting value can be a string or another variable (0.9.0).

Support for combinations of multiple variables may be added in the future.

comment:2 by Ronaldo Pontes, 10 years ago

I would also like to base map conditions on existing variables...

map $host $public_domain {



map $http_referer $landing_request {


*.$public_domain 0; # THIS DOESNT WORK !!!
default 1;


Last edited 10 years ago by Ronaldo Pontes (previous) (diff)

comment:3 by Maxim Dounin, 10 years ago

It's not clear what you are trying to do with the example, as it's expected to always return 0 if the line in question will work. But anyway, there are no plans to support variables in source values.

comment:4 by Ronaldo Pontes, 10 years ago

Just updated the comment. It was meant to compare the $http_referer with $public_domain.

comment:5 by kevin, 8 years ago

Had another request for this feature today.

comment:6 by xeioex, 8 years ago

In 6535:db699978a33f/nginx:

(The changeset message doesn't reference this ticket)

comment:7 by xeioex, 8 years ago

Resolution: fixed
Status: acceptedclosed

Support of complex values in resulting strings are available in nginx 1.11.0.

Version 2, edited 8 years ago by xeioex (previous) (next) (diff)
Note: See TracTickets for help on using tickets.