Opened 3 years ago

Closed 19 months ago

Last modified 19 months ago

#663 closed enhancement (fixed)

Variable interpolation inside Map directive

Reported by: ronaldocpontes@… Owned by:
Priority: minor Milestone:
Component: nginx-module Version: 1.7.x
Keywords: map, interpolation Cc:
Sensitive: no
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

Description

http://stackoverflow.com/questions/26976535/variable-interpolation-inside-map-directive

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 Changed 3 years ago by mdounin

  • Status changed from new to accepted
  • Type changed from defect to enhancement

This is expected behaviour. Only a single variable can be used as a resulting value, see http://nginx.org/r/map:

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 Changed 3 years ago by ronaldocpontes@…

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

map $host $public_domain {

default example.com;

}

map $http_referer $landing_request {

hostnames;

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

}

Last edited 3 years ago by ronaldocpontes@… (previous) (diff)

comment:3 Changed 3 years ago by mdounin

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 Changed 3 years ago by ronaldocpontes@…

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

comment:5 Changed 22 months ago by kevin

Had another request for this feature today.

comment:6 Changed 19 months ago by xeioex

In 6535:db699978a33f/nginx:

(The changeset message doesn't reference this ticket)

comment:7 Changed 19 months ago by xeioex

  • Resolution set to fixed
  • Status changed from accepted to closed

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

Last edited 19 months ago by xeioex (previous) (diff)
Note: See TracTickets for help on using tickets.