Welcome! Log In Create A New Profile

Advanced

Re: Regex on Variable ($servername)

Francis Daly
November 10, 2017 09:06AM
On Fri, Nov 10, 2017 at 12:02:28PM +0100, basti wrote:

Hi there,

> the Problem are "multiple" subs.
>
> When I use your example i get
>
> curl -H Host:foo.www.example.com http://localhost/
> domain is foo.www.example.com

Yes - the example config you gave very specifically ignores "www." at
the start of the Host: header, and sets $domain to the rest.

If you want a different part of the Host header, you must decide what
exactly you want, and write a config that does that.

> But I need example.com like here https://regex101.com/r/9h3D77/1

I think that that says you want the capturing regex (\w+\.\w+)$ so that
you will keep the last two dot-separated parts, such that www.example.com
becomes example.com and www.example.co.uk becomes co.uk

Without testing, I'd guess that

server_name ~ (?<domain>\w+\.\w+)$;

probably comes close to what you want, assuming that your regex engine
inside your nginx supports \w.

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Regex on Variable ($servername)

basti October 29, 2017 06:54AM

Re: Regex on Variable ($servername)

Francis Daly November 10, 2017 03:20AM

Re: Regex on Variable ($servername)

basti November 10, 2017 06:04AM

Re: Regex on Variable ($servername)

Francis Daly November 10, 2017 09:06AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 288
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready