0

I have a config file that look like this:

server {
    listen 80;

    server_name ~^(?<folder>[^.]+).(?<user>[^.]+).example.com;
    charset utf-8;
    index index.php index.html index.htm;
    root /var/www/projects/dev/$user/$folder/htdocs;
...
}

so i can access to the site with a url like test.user.example.com.

In one server the config file is working as expected but in other server the variables are void.

Any idea ?

3pepe3
  • 573
  • 6
  • 23
  • 1
    Just FYI: to match dots, you need to escape them when outside of a character class, `^(?[^.]+)\.(?[^.]+)\.example\.com` – Wiktor Stribiżew Jul 30 '18 at 08:24
  • One of your server blocks will be the *default server* and will process requests even if the host name does not match the regular expression - which will mean that the variables will be void. See [this question](https://stackoverflow.com/questions/9824328/why-is-nginx-responding-to-any-domain-name) for more. – Richard Smith Jul 30 '18 at 08:39

1 Answers1

0

The solution was to modify the regex from

server_name ~^(?<folder>[^.]+)\.(?<user>[^.]+).example.com;

to

server_name ~^(?<folder>[^.]*).(?<user>[^.]*).example.com;
3pepe3
  • 573
  • 6
  • 23