S
S
Sergey Petrikov2013-10-15 20:32:57
Nginx
Sergey Petrikov, 2013-10-15 20:32:57

Help with nginx regex

There is a config, something like this

server {
    listen 80;
    server_name ~^(?:www\.)?(?P<host_wo_www>.+)$;
    server_name_in_redirect     off;
    resolver    127.0.0.1;

Accordingly, the full domain name without www gets into the $host_wo_www variable, but I need to get one more variable so that only the third-level subdomain gets there, that is, we have www.subdomain.domain.com, I need to have a variable where only the subdomain gets, maybe someone help with the routine?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Nagaev, 2013-11-30
@RicoX

I got this:
server_name ~^(?:www\.)?(?P.+)?\.(?P[^\.]+\.[^\.]+)$;
If there are more than 3 parts in the domain, then the "extra" ones go to the subdomain:
abc.def.ghi.ru ->abc.def + ghi.ru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question