0

I have several domain names and several document root, like that :

toto.exemple.com /var/www/exempleOne
titi.exemple.com /var/www/exempleTwo
[...]

Basically what I want to do, is using only one server block / vhost file for all the domains.

I tried to used nginx map for this, and did the following :

map $host $docroot{
  toto.exemple.com /var/www/exempleOne;
  titi.exemple.com /var/www/exempleTwo;
}

server {
    listen 80;
    server_name _;
        location / {
          root   $docroot;
          expires           30d;
        }
}

But it doesn't seem to work, it seems like nginx is using the default document root (/etc/nginx/html/).

1 Answers1

1

You could try using $http_host as the variable instead of $host in the map.

Then, you could also use a default item in the map, setting it to some default value.

This way one can see if nginx evaluates the map at all for the root statement. If nginx tries to fetch data from the default directory, then it means that something is wrong with the variable map is using.

If it still fetches from the nginx default root directory, then it means that nginx does not correctly evaluate the map here.

I would also recommend setting the root outside the location / block.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58