nginx set variable in location
Variables can't be declared anywhere nor be used in any directive.
As the documentation of
set directive is :
Syntax: set $variable value; Default: — Context: server, location, if
The immediate consequence is that you can't use custom variables in an
Update : after a discussion and experiments with AlexeyTen in this chatroom.
access_logcan contain variables with restrictions. Among them, the lack of buffering and the fact that the leading slash must not be declared in a variable.
error_logwon't work with variables at all.
rootdirective can contains variables.
server_namedirective only allows strict
$hostnamevalue as a variable-like notation.