nginx dynamic servername with regular expression doesn't work for co.uk

Posted by redn0x on Server Fault See other posts from Server Fault or by redn0x
Published on 2013-10-21T14:32:16Z Indexed on 2013/10/21 15:56 UTC
Read the original article Hit count: 346

Filed under:
|
|
|
|

I'm trying to setup a nginx server which dynamically loads content from a folder for a domain. To do this I'm using regular expressions in the server name like so:

server_name ((?<subdomain>.+)\.)?(?<domain>.+)\.(?<tld>.*);

This will create a 3 variables for nginx to use later on, for example when using the following url: test.foo.example.com this will evaluate to:

  1. $subdomain = test.foo
  2. $domain = example
  3. $tld = com

The problem arises when the co.uk top-level domain is used. In this case when using the url test.foo.example.co.ukit will evaluate to:

  1. $subdomain = test.foo.cedira
  2. $domain = co
  3. $tld = uk

How can I edit the regular expression so that it will also work for co.uk?

© Server Fault or respective owner

Related posts about nginx

Related posts about http