Map with two variables

Hi,

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[^.]).(?P[^.]).(?P[^.]*)” $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/nginx.pid
–http-log-path=/var/log/nginx/access.log
–error-log-path=/var/log/nginx/error.log
–add-module=/usr/local/src/ngx_devel_kit
–add-module=/usr/local/src/lua-nginx-module
–add-module=/usr/local/src/headers-more-nginx-module/
–add-module=/usr/local/src/nginx-statsd --with-http_spdy_module
–with-http_sub_module

Regards,
Matthias

it would be easier to define server_name with regexp and use match
groups

server {
server_name ~ ^(?\w+).(?\w+).(?\w+)$;

set $graphite_host “${a}${b}${c}”;
}

09.03.15 18:36, Matthias R. пишет:

work, but not $a_$b or $a$b. I always get an error like:
–http-log-path=/var/log/nginx/access.log


nginx mailing list
[email protected]
nginx Info Page


br,
Dmitry Pryadko