<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle19
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Ping<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Eran<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Eran Kornblau <br>
<b>Sent:</b> Monday, March 6, 2017 9:53 PM<br>
<b>To:</b> nginx-devel@nginx.org<br>
<b>Subject:</b> Add support for 'define' directive<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Hi all,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I would like to add support for a ‘define’ directive to nginx, which will allow text substitutions during conf parsing.<o:p></o:p></p>
<p class="MsoNormal">At this point I’m thinking about adding support only for simple macros – no parameters, no ifdefs etc.<o:p></o:p></p>
<p class="MsoNormal">Before I start working on the code, I wanted to check whether this makes sense to you and whether you’ll be
<br>
willing to merge it (assuming it’s implemented well, of course).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">A sample configuration may look like this:<o:p></o:p></p>
<p class="MsoNormal">nginx.conf:<o:p></o:p></p>
<p class="MsoNormal">…<o:p></o:p></p>
<p class="MsoNormal">define extra_log_args ‘$http_my_param $arg_some_arg’<o:p></o:p></p>
<p class="MsoNormal">…<o:p></o:p></p>
<p class="MsoNormal">include child.conf<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">child.conf:<o:p></o:p></p>
<p class="MsoNormal">…<o:p></o:p></p>
<p class="MsoNormal">log_format main '$remote_addr - $remote_user [$time_local] "$request" '<o:p></o:p></p>
<p class="MsoNormal"> '$status $bytes_sent $request_time "$http_referer" '<o:p></o:p></p>
<p class="MsoNormal"> %extra_log_args%;<o:p></o:p></p>
<p class="MsoNormal">…<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In terms of implementation, the define command will add the key/value to a new rbtree on ngx_conf_t.<o:p></o:p></p>
<p class="MsoNormal">In ngx_conf_read_token, next to the code that decodes \r,\n etc., the defined keys will be expanded<br>
to their values. Since the expansion is performed within an arg, this implies that a define cannot map to
<br>
multiple args – it will essentially be like an nginx variable except that it’s evaluated during conf parsing.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">An example of a use case where this could be useful (from our production environment) –
<o:p></o:p></p>
<p class="MsoNormal">We have multiple types of nginx servers, for example, some serve vod content, and some serve live video
<br>
content. In addition to that, we have multiple data centers. The configuration of these servers is different
<br>
but there are many common parts. Our way to share these common parts is to create small shared conf
<br>
files and have them included by the server-specific configuration files. So we have <server types>x<sites><br>
root conf files that include other files. On each server, nginx.conf is a symbolic link to the root conf<br>
matching the specific server. In some cases, some internal conf file has parts that depend on the site,<br>
and the problem is that we don’t have a way to propagate the id of the site from the root conf to this<br>
child conf. We can probably do it with ‘set’, but that would be less optimal since there’s no reason to have
<br>
this value dynamic.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Any feedback is welcome<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thank you <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Eran<o:p></o:p></p>
</div>
</body>
</html>