Well I have a slightly different question than this one: I don't want to map two variables at the same time, I want to map one variable using two others as parameters.

Indeed I have read in the documentation about the map directive that:

Before version 0.9.0 only a single variable could be specified in the first parameter.

So, as I have nginx 1.8, I expect to be able to use more than a single variable in the first parameter.

This led me to think that I could write something like the two last map directives in this example:

map $http_user_agent $bot {
    default         "";
    "~*Googlebot"   "yes";
    "~*MJ12bot"     "yes";
    "~*bingbot"     "yes";

map $request        $bot    $np {
    default         ""      "";
    default         "yes"   "";
    "~*newproject"  ""      "yes";
    "~*newproject"  "yes"   "";

map $bot    $np     $regular {
    ""      ""      "yes";
    ""      "yes"   "";
    "yes"   ""      "";

But it doesn't work (nginx -t returns a

invalid number of arguments in "map" directive


So, how is it possible to specify several variables in the first parameter? Or, what does actually mean the documentation, if I misunderstood it?

  • I've added an answer to the question, but actually this question looks like an XY-problem meta.stackexchange.com/questions/66377/what-is-the-xy-problem
    – Alexey Ten
    Feb 29, 2016 at 7:22
  • Maybe it's kind of (and I didn't know about them). But I was truly thinking it's actually not possible and there's something I miss to understand in the documentation. It's clear now.
    – zezollo
    Feb 29, 2016 at 8:04

1 Answer 1


You have misunderstood nginx's docs. It means that before version 0.9 first argument of the map must be single variable and nothing else. Since version 0.9.0 first argument could be any string with any number of variables to interpolate.

Here how your first block could look like:

map "$bot:$request"      $np {
    default              "";
    "~^yes:"             "";
    "~*^:.*newproject"   "yes";

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .