Forum: NGINX Inconsistency in ability to use variables in nginx config

2974d09ac2541e892966b762aad84943?d=identicon&s=25 miguel_hamster (Guest)
on 2013-11-13 07:26
(Received via mailing list)
It seems like it's possible to use variables in some configuration
directives but not in others. This works:

root /usr/www/$sitename/httpdocs;

works, while these:

access_log /var/log/www/$sitename/access.log;
proxy_cache $sitename;

do not, instead generating errors when I try to restart nginx.

Is there any documentation that explains where I can and cannot use a
variable? Or is there some syntax I should be using to indicate variable
interpolation? It would be immensely helpful if they worked in all these
contexts, because then we wouldn't have to repeat so much across
different
site configuration files, leading to the requirement for generating them
with clunky scripts. As it is, the variables are of very limited
utility.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,244605,244605#msg-244605
40b4c848b8fcd63b0cb60b9d170c3a77?d=identicon&s=25 Valentin V. Bartenev (Guest)
on 2013-11-13 11:16
(Received via mailing list)
On Wednesday 13 November 2013 10:25:44 miguel_hamster wrote:
> It seems like it's possible to use variables in some configuration
> directives but not in others. This works:
>
> root /usr/www/$sitename/httpdocs;
>
> works, while these:
>
> access_log /var/log/www/$sitename/access.log;

This should work too.  See documentation: http://nginx.org/r/access_log

> proxy_cache $sitename;
>
> do not, instead generating errors when I try to restart nginx.
>
> Is there any documentation that explains where I can and cannot use a
> variable?

See official docs: http://nginx.org/en/docs/
It's usually explicitly stated if directive supports variables

> Or is there some syntax I should be using to indicate variable
> interpolation? It would be immensely helpful if they worked in all these
> contexts, because then we wouldn't have to repeat so much across different
> site configuration files, leading to the requirement for generating them
> with clunky scripts. As it is, the variables are of very limited utility.

Yes, it is.  Variables in nginx are not supposed to replace template
engines
or special configuration-generation tools.

See FAQ: http://nginx.org/en/docs/faq/variables_in_config.html

Also, some duplication in config isn't something horrible.  Nginx
configuration
is not a programming language, it utilizes another paradigm and trying
to be
declarative.

  wbr, Valentin V. Bartenev
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.