Forum: NGINX Regular expression used in server_name directive

Posted by justin (Guest)
on 2013-03-03 18:44
(Received via mailing list)
I am using a regular expression with a capture group in my server_name
directive. It looks like:

    server_name (?<account>.+)\.mydomain\.com$

The problem is that I want to expand it slightly and say anything except
web3.mydomain.com. I.E.

   something.mydomain.com matches, but web3.mydomain.com does not match.

How is this possible?

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,236870,236870#msg-236870
Posted by Francis Daly (Guest)
on 2013-03-03 20:13
(Received via mailing list)
On Sun, Mar 03, 2013 at 12:43:57PM -0500, justin wrote:

Hi there,

> I am using a regular expression with a capture group in my server_name
> directive. It looks like:
>
>     server_name (?<account>.+)\.mydomain\.com$

http://nginx.org/r/server_name for details of how the matching server{}
block is chosen.

> The problem is that I want to expand it slightly and say anything except
> web3.mydomain.com. I.E.
>
>    something.mydomain.com matches, but web3.mydomain.com does not match.
>
> How is this possible?

Make a different server{} block that matches web3.mydomain.com.

  f
--
Francis Daly        francis@daoine.org
Posted by justin (Guest)
on 2013-03-03 20:21
(Received via mailing list)
I actually have a working regular expression which should work now:

   server_name ^(?!web3\.)(?<account>.+)\.mydomain\.com$;

But for some odd reason when I restart nginx, I am getting:

  nginx: [emerg] unknown "account" variable

This should work though, right?

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,236870,236876#msg-236876
Posted by Francis Daly (Guest)
on 2013-03-03 21:05
(Received via mailing list)
On Sun, Mar 03, 2013 at 02:21:10PM -0500, justin wrote:

Hi there,

> I actually have a working regular expression which should work now:
>
>    server_name ^(?!web3\.)(?<account>.+)\.mydomain\.com$;

http://nginx.org/r/server_name

Pay particular attention to the line that begins "It is also possible
to use regular expressions in server names".

> But for some odd reason when I restart nginx, I am getting:
>
>   nginx: [emerg] unknown "account" variable

Did you get that message when you tested with your initial version too?

  f
--
Francis Daly        francis@daoine.org
Posted by justin (Guest)
on 2013-03-03 21:16
(Received via mailing list)
No, simply doing

server_name ~^(?<account>.+)\.mydomain\.com$;

Works. This may be a bug with nginx? The new regular expression is valid 
and
should work.

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,236870,236881#msg-236881
Posted by Francis Daly (Guest)
on 2013-03-03 22:39
(Received via mailing list)
On Sun, Mar 03, 2013 at 03:16:09PM -0500, justin wrote:

Hi there,

> server_name ~^(?<account>.+)\.mydomain\.com$;
>
> Works.

Correct.

Now compare that line with the server_name lines in the previous mails.

> This may be a bug with nginx?

No.

> The new regular expression is valid and should work.

Yes; nginx is happy with the regular expression, provided that it knows
that it is intended to be a regular expression.

  f
--
Francis Daly        francis@daoine.org
Posted by justin (Guest)
on 2013-03-04 00:17
(Received via mailing list)
My bad, stupid mistake, forgot the ^.

Working fine now. Thanks.

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,236870,236887#msg-236887
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.