nginx dynamic servername with regular expression doesn't work for co.uk
- by redn0x
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:
$subdomain = test.foo
$domain = example
$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:
$subdomain = test.foo.cedira
$domain = co
$tld = uk
How can I edit the regular expression so that it will also work for co.uk?