#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 |
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 by , 10 years ago
Status: | new → accepted |
---|---|
Type: | defect → enhancement |
comment:2 by , 10 years ago
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;
}
comment:3 by , 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 , 10 years ago
Just updated the comment. It was meant to compare the $http_referer with $public_domain.
Cheers
comment:7 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
Support of complex values in resulting strings are available in nginx 1.11.0.
This is expected behaviour. Only a single variable can be used as a resulting value, see http://nginx.org/r/map:
Support for combinations of multiple variables may be added in the future.