<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Hi</p>
<p>I'm trying to <i>clean</i> up a config file and I'm having a
headache trying to do it.</p>
<p>Consider the following scenario:</p>
<ul>
<li>Users from group gfoo must be allowed to GET URL foo, while
adminfoo must be able to POST<br>
</li>
<li>Users from group gbar must be allowed to GET URL bar, while
adminbar must be able to POST</li>
<li>...and so on for ~50 groups.</li>
</ul>
<p>The configuration at this moment is similar to:<br>
</p>
<blockquote><font face="Courier New, Courier, monospace">server {</font><br>
<font face="Courier New, Courier, monospace"> listen 80;</font><br>
<font face="Courier New, Courier, monospace"> server_name
foo.domain.com;</font><br>
<font face="Courier New, Courier, monospace"> location ~
/content/foo {</font><br>
<font face="Courier New, Courier, monospace"> if
($denied_foo) {</font><br>
<font face="Courier New, Courier, monospace"> return
403 "Forbidden";</font><br>
<font face="Courier New, Courier, monospace"> }</font><br>
<font face="Courier New, Courier, monospace"> ...</font><br>
<font face="Courier New, Courier, monospace"> }</font><br>
<font face="Courier New, Courier, monospace"><font face="Courier
New, Courier, monospace"> location ~ /page/bar/action...and
~10 locations more per server...</font></font><br>
<font face="Courier New, Courier, monospace">}</font><br>
<font face="Courier New, Courier, monospace">server {</font><br>
<font face="Courier New, Courier, monospace">
listen 80;</font><br>
<font face="Courier New, Courier, monospace">
server_name bar.domain.com;</font><br>
<font face="Courier New, Courier, monospace">
location ~ /content/bar {</font><br>
<font face="Courier New, Courier, monospace">
if ($denied_bar) {</font><br>
<font face="Courier New, Courier, monospace">
return 403 "Forbidden";</font><br>
<font face="Courier New, Courier, monospace">
}</font><br>
<font face="Courier New, Courier, monospace">
...</font><br>
<font face="Courier New, Courier, monospace"> }</font><br>
<font face="Courier New, Courier, monospace"> location ~
/page/bar/action...and ~10 locations more per server...</font><br>
<font face="Courier New, Courier, monospace">}</font><br>
<font face="Courier New, Courier, monospace">...~200
whatever.domain.com servers more<br>
</font><font face="Courier New, Courier, monospace">map
$request_method:$request_uri:$http_groups $denied_foo {</font><br>
<font face="Courier New, Courier, monospace"> default 1;</font><br>
<font face="Courier New, Courier, monospace">
~^GET:/content/foo:gfoo 0;</font><br>
<font face="Courier New, Courier, monospace"><font face="Courier
New, Courier, monospace"> ~^POST:/content/foo:adminfoo 0;</font></font><br>
<font face="Courier New, Courier, monospace">}</font><br>
<font face="Courier New, Courier, monospace">map
$request_method:$request_uri:$http_groups $denied_bar {</font><br>
<font face="Courier New, Courier, monospace">
default 1;</font><br>
<font face="Courier New, Courier, monospace">
~^GET:/content/bar:gbat 0;</font><br>
<font face="Courier New, Courier, monospace">
</font><font face="Courier New, Courier, monospace"><font
face="Courier New, Courier, monospace">
~^POST:/content/bar:adminbar 0;</font></font><br>
<font face="Courier New, Courier, monospace"><font face="Courier
New, Courier, monospace"> </font>}</font><br>
<font face="Courier New, Courier, monospace">...lots of map
directives</font><br>
</blockquote>
<p><br>
</p>
<p>I'll like to be able to simplify it doing something like:</p>
<blockquote>
<p><font face="Courier New, Courier, monospace"> server_name
(?<myvar>.*)\.domain\.com;<br>
...<br>
map $request_method:$request_uri:$http_groups $denied {<br>
default 1;<br>
~^GET:/content/$myvar:g$myvar 0;<br>
~^POST:/content/$myvar:admin$myvar 0;<br>
</font> <font face="Courier New, Courier, monospace">}</font></p>
</blockquote>
I have even tried using an auxiliary map this way:<br>
<blockquote>
<p><font face="Courier New, Courier, monospace">map $servername
$myvar {</font><br>
<font face="Courier New, Courier, monospace">
~^(?<v>.*)\.domain\.com $v;</font><br>
<font face="Courier New, Courier, monospace"> }</font></p>
<p><font face="Courier New, Courier, monospace">map
$request_method:$request_uri:$http_groups $denied {<br>
default 1;<br>
~^GET:/content/$myvar:g$myvar 0;<br>
~^POST:/content/$myvar:admin$myvar 0;<br>
</font> <font face="Courier New, Courier, monospace">}</font></p>
</blockquote>
<p>But I haven't succeeded so far. Could you help me?</p>
<p>Having ~200 configuration files doesn't seem a good option, so
omit "on-build config with script parameters"<br>
</p>
<p>Thanks in advance,</p>
<p>Regards.<font face="Courier New, Courier, monospace"><br>
</font></p>
<p><font face="Courier New, Courier, monospace"><br>
</font></p>
</body>
</html>