Anonymous User
January 10, 2014 05:34PM
I want to extract just the "domain" and "extension" parts from an nginx
server_name for use as variables later in nginx conf.

For example,

server_name <some PERL regex ... ?<domain> ... ?<extension>
location = /test.html {
alias /local/path/to/$domain.$extension.html;

No matter what the server_name contains, from




and variations in between,the result should be

$domain = mydomain
$extension = tld

I found this post

"Perl Regex to get the root domain of a URL"

that suggest this perl regex


works to extract & return "domain.tld" from any from of input URI.

What's the right form of that regex in nginx's server_name to populate
<domain> and <extension> variables for subsequent use?

nginx mailing list
Subject Author Posted

perl regex to extract "domain" and "extension" into variables from 'server_name'

Anonymous User January 10, 2014 05:34PM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 125
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready