view xml/en/docs/faq/variables_in_config.xml @ 3054:0083dce686ec

Free nginx: repository links. Repositories are now under freenginx.org/hg/. Only essential repositories are preserved for now: in particular, dev examples are no longer provided, so the relevant section from the devguide was removed.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 14 Feb 2024 20:07:38 +0300
parents 764fbac1b8b4
children
line wrap: on
line source

<!--
  Copyright (C) Nginx, Inc.
  -->

<!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">

<article name="Is there a proper way to use nginx variables to
               make sections of the configuration shorter,
               using them as macros for making
               parts of configuration work as templates?"
         link="/en/docs/faq/variables_in_config.html"
         lang="en"
         rev="1">

<section>

<para>
<initial>Q:</initial>
Is there a proper way to use nginx variables to make sections of
the configuration shorter, using them as macros for making
parts of configuration work as templates?
</para>

<para>
&nbsp;
</para>

<para>
<initial>A:</initial>
Variables should not be used as template macros. Variables are
evaluated in the run-time during the processing of each
request, so they are rather costly compared to plain static
configuration. Using variables to store static strings is also
a bad idea. Instead, a macro expansion and "include" directives
should be used to generate configs more easily and it can be
done with the external tools, e.g. sed + make or any other
common template mechanism.
</para>

</section>

</article>