Welcome! Log In Create A New Profile

Advanced

Using variables on configuration (map?) for regex

mostolog@gmail.com
July 22, 2016 02:24AM
Hi

I'm trying to /clean/ up a config file and I'm having a headache trying
to do it.

Consider the following scenario:

* Users from group gfoo must be allowed to GET URL foo, while adminfoo
must be able to POST
* Users from group gbar must be allowed to GET URL bar, while adminbar
must be able to POST
* ...and so on for ~50 groups.

The configuration at this moment is similar to:

server {
listen 80;
server_name foo.domain.com;
location ~ /content/foo {
if ($denied_foo) {
return 403 "Forbidden";
}
...
}
location ~ /page/bar/action...and ~10 locations more per server...
}
server {
listen 80;
server_name bar.domain.com;
location ~ /content/bar {
if ($denied_bar) {
return 403 "Forbidden";
}
...
}
location ~ /page/bar/action...and ~10 locations more per server...
}
...~200 whatever.domain.com servers more
map $request_method:$request_uri:$http_groups $denied_foo {
default 1;
~^GET:/content/foo:gfoo 0;
~^POST:/content/foo:adminfoo 0;
}
map $request_method:$request_uri:$http_groups $denied_bar {
default 1;
~^GET:/content/bar:gbat 0;
~^POST:/content/bar:adminbar 0;
}
...lots of map directives


I'll like to be able to simplify it doing something like:

server_name (?<myvar>.*)\.domain\.com;
...
map $request_method:$request_uri:$http_groups $denied {
default 1;
~^GET:/content/$myvar:g$myvar 0;
~^POST:/content/$myvar:admin$myvar 0;
}

I have even tried using an auxiliary map this way:

map $servername $myvar {
~^(?<v>.*)\.domain\.com $v;
}

map $request_method:$request_uri:$http_groups $denied {
default 1;
~^GET:/content/$myvar:g$myvar 0;
~^POST:/content/$myvar:admin$myvar 0;
}

But I haven't succeeded so far. Could you help me?

Having ~200 configuration files doesn't seem a good option, so omit
"on-build config with script parameters"

Thanks in advance,

Regards.


_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Using variables on configuration (map?) for regex

mostolog@gmail.com July 22, 2016 02:24AM

Re: Using variables on configuration (map?) for regex

Francis Daly July 23, 2016 04:30AM

Re: Using variables on configuration (map?) for regex

mostolog@gmail.com July 25, 2016 04:44AM

Re: Using variables on configuration (map?) for regex

Francis Daly July 25, 2016 02:44PM

Re: Using variables on configuration (map?) for regex

mostolog@gmail.com July 26, 2016 02:24AM

Re: Using variables on configuration (map?) for regex

mostolog@gmail.com January 24, 2017 04:22AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 315
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready