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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C240d863e2774559cb7f41b924e03a47?d=identicon&s=25 unknown (Guest)
on 2014-01-10 23:33
(Received via mailing list)
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

  mydomain.tld

to

  https://www.mydomain.tld:80/something

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"
   http://stackoverflow.com/questions/15627892/perl-r...

that suggest this perl regex

  ^.*://(?:[wW]{3}\.)?([^:/]*).*$

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?
This topic is locked and can not be replied to.