Regular expressions in server_name: pattern length

Igor Sysoev igor at sysoev.ru
Wed Dec 9 13:09:31 MSK 2009


On Wed, Dec 09, 2009 at 09:44:01AM +0000, Phillip Oldham wrote:

> Igor Sysoev wrote:
> > On Wed, Dec 09, 2009 at 09:21:24AM +0000, Phillip Oldham wrote:
> >
> >   
> >> Is it possible to capture the length of a particular pattern in the 
> >> server_name section?
> >>
> >> For example, I'm having trouble getting the following to match:
> >>
> >> server_name ~([a-z]{2,3})?\d{3,6}\.mysite\.org;
> >>
> >> I'm using 0.7.62.
> >>     
> >
> > Do you mean how to learn the caputured data length ? No way.
> >   
> 
> To clarify, I'm looking to be able to capture:
> 
> asd12345.mysite.org
> xy789.mysite.org
> 
> but using a separate rule capture:
> 
> client1.mysite.org
> anotherclient.mysite.org
> 
> for a different `server` block.
> 
> This is not possible then?

It's possible:

server {
     server_name ~^([a-z]{2,3})?\d{3,6}\.mysite\.org$;
}

server {
     server_name ~^(\w+)\.mysite\.org$;
}

You may also control the order of sites.


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



More information about the nginx mailing list