map with two variables

Dmitry Pryadko dp at nginx.com
Thu Mar 12 11:08:16 UTC 2015


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

server {
   server_name ~ ^(?<a>\w+)\.(?<b>\w+)\.(?<c>\w+)$;

   set $graphite_host "${a}_${b}_${c}";
}

09.03.15 18:36, Matthias Rieber пишет:
> 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<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/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
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>

-- 
br,
Dmitry Pryadko



More information about the nginx mailing list