map with two variables

Matthias Rieber ml-nginx at
Mon Mar 9 15:36:00 UTC 2015


I'd like to set a variable to the value of $host where the dots are 
replaced by underscore. My first idea:

map $host $graphite_host {
   "~(?P<a>[^.]*)\.(?P<b>[^.]*)\.(?P<c>[^.]*)" $a_$b_$c;

But I can't use more than one variable in the result. $a or $b would 
work, but not $a_$b or $a$b. I always get an error like:
nginx: [emerg] unknown "a$b" variable. Is that intentional? Is there any 
other way to replace the . by _?

# nginx -V
nginx version: nginx/1.7.10
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
TLS SNI support enabled
configure arguments: --with-http_stub_status_module 
--with-http_ssl_module --prefix=/usr/local 
--conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/ 
--add-module=/usr/local/src/nginx-statsd --with-http_spdy_module 


More information about the nginx mailing list