Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable interpolation inside Map directive

Tags:

nginx

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;
        }

    }

}

Do you have any suggestions to make the expansion work inside the map?

like image 540
user745079 Avatar asked Sep 29 '22 09:09

user745079


1 Answers

As stated in the map directive documentation :

The resulting value can be a string or another variable (0.9.0).

Update: This functionality has been added to version 1.11.2 of NGinx, as per Comment #7 here: https://trac.nginx.org/nginx/ticket/663#comment:7

like image 113
Xavier Lucas Avatar answered Oct 04 '22 03:10

Xavier Lucas