Vhost support

Igor Sysoev igor at sysoev.ru
Sat Jan 29 11:00:02 MSK 2011


On Sat, Jan 29, 2011 at 05:35:19PM +1000, Mark Constable wrote:

> On 29/01/11, Igor Sysoev wrote:
> > > This is pretty good but I want to reverse the domain.org $host
> > > variable and provide, say, a $rhost variable of "org/domain".
> > [...]
> >
> > http://nginx.org/en/docs/http/server_names.html#regex_names
> 
> Thanks for the reply, but how do I take into account...
> 
> domain.com
> www.domain.com
> www.username.domain.com
> 
> so, ie; the first one becomes com/domain and the last one becomes
> com/domain/username/www ?
> 
> I have tried this but couldn't get it to work...
> 
>   server {
>     server_name  ~^(?<p1>\.)?(?<p2>\.)?(?<p3>\.)?(?<p4>\.)?(?<p5>\.);
>     #server_name  ~^(?P<p1>\.)?(?P<p2>\.)?(?P<p3>\.)?(?P<p4>\.)?(?P<p5>\.);
>     location / {
>       root /var/www/$p5/$p4/$p3/$p2/$p1;
>     }
>   }

Make several servers with different regexes:

server {
  server_name  ~^(?<p1>[^\.]+)\.(?<p2>[^\.]+)\.(?<p3>[^\.]+)\.(?<p4>[^\.]+)$;
  location / {
    root /var/www/$p4/$p3/$p2/$p1;
  }
}

server {
  server_name  ~^(?<p1>[^\.]+)\.(?<p2>[^\.]+)\.(?<p3>[^\.]+)$;
  location / {
    root /var/www/$p3/$p2/$p1;
  }
}

server {
  server_name  ~^(?<p1>[^\.]+)\.(?<p2>[^\.]+)$;
  location / {
    root /var/www/$p2/$p1/www;
  }
}


-- 
Igor Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list