Forum: NGINX Would "root" allow for captures?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 Michael Shadle (Guest)
on 2009-04-10 07:36
(Received via mailing list)
i'd like to do something like:

server {
   listen 80;
   server_name *.user.foo.com;
   root /home/user/web/$1;
}

this would be basically required too:

server {
   listen 80;
   server_name *.user.foo.com;
   root /home/user/web/$1;
   if ($1 == 'something) {
      require include.conf;
   }
}

it would be nice if i could assign "user" as a variable too. however,
that would be a double bonus.

i think alias allows captures, but i would need to define
DOCUMENT_ROOT then as well.

ideas?
96dfd0f0a8399d3b03feba1e6a562e0a?d=identicon&s=25 Edho P Arief (Guest)
on 2009-04-10 08:04
(Received via mailing list)
perhaps this?

On Fri, Apr 10, 2009 at 12:24 PM, Michael Shadle <mike503@gmail.com>
wrote:
> i'd like to do something like:
>
> server {
>   listen 80;
>   server_name *.user.foo.com;
server_name (.*?).user.foo.com;
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-04-10 08:10
(Received via mailing list)
On Thu, Apr 09, 2009 at 10:24:12PM -0700, Michael Shadle wrote:

> i'd like to do something like:
>
> server {
>    listen 80;
>    server_name *.user.foo.com;

     server_name ~^(.+)\.user\.foo\.com$;

>       require include.conf;
>    }
> }

This i ssome kind of configuration macro, but it's currently not easy
to implement this.

> it would be nice if i could assign "user" as a variable too. however,
> that would be a double bonus.
>
> i think alias allows captures, but i would need to define
> DOCUMENT_ROOT then as well.

The "root" supports captures too.
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 Michael Shadle (Guest)
on 2009-04-10 08:18
(Received via mailing list)
2009/4/9 Igor Sysoev <is@rambler-co.ru>:

>     server_name ~^(.+)\.user\.foo\.com$;

awesome! it works.

>>    if ($1 == 'something) {
>>       require include.conf;
>>    }

> This i ssome kind of configuration macro, but it's currently not easy
> to implement this.

really? why is that? seems like it should be pretty straightforward,
but you know your code the best.

> The "root" supports captures too.

just figured that out - excellent :)
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 Michael Shadle (Guest)
on 2009-04-11 19:36
(Received via mailing list)
On Thu, Apr 9, 2009 at 11:11 PM, Michael Shadle <mike503@gmail.com>
wrote:
>> This i ssome kind of configuration macro, but it's currently not easy
>> to implement this.

This would also work

include /etc/nginx/$1.conf;

but I would want to test for the existence first.

if (-f /etc/nginx/$1.conf) {
   include /etc/nginx/$1.conf;
}

so it is not easy to do if ($1 == 'something') {} ? if so, then we
just need to say that include is allowed inside of an if block :)
This topic is locked and can not be replied to.