Skip to content

[mixed_case_variable] Mixed-case variable references

What this check looks for

This plugin flags the same variable referenced with more than one casing in one configuration, for example $My_Var in one directive and $MY_VAR in another.

Why this is a problem

NGINX lowercases variable names when it reads the configuration, so $My_Var, $my_var and $MY_VAR are one variable. Written with different casings they look like two, which hides what the configuration does and usually means one spelling was meant to be a different variable.

Bad configuration

server {
    location / {
        set $My_Var "hello";
        proxy_pass http://backend/$MY_VAR;
    }
}

$My_Var and $MY_VAR are the same variable.

Better configuration

Use one lowercase spelling throughout:

server {
    location / {
        set $my_var "hello";
        proxy_pass http://backend/$my_var;
    }
}

Additional notes

  • This applies to every variable: those defined with set, map and geo, built-in ones such as $http_* and $arg_*, and named captures. A capture (?<Name>...) is lowercased too, so $Name and $name are the same variable.
  • Only values NGINX expands are checked. Regular expressions (location ~, if (... ~ ...), rewrite patterns, server_name ~ and the ~ pattern of proxy_redirect and proxy_cookie_*) are skipped: there $Name is an end-of-string anchor followed by Name, and \$Name a literal dollar sign. Literal names (server_name, valid_referers) are skipped too. A value is checked even when it starts with ~, and "\$Name" in a value still references $name, because the backslash does not escape $.