1

At beginning, I created a conf file that work correctly when I want to access to http://www.domain.com :

server {
   listen 80;
   listen [::]:80;

   root /var/www/domain;
   index index.html

   server_name domain.com www.domain.com;
}

Then I decide to create another conf file for a subdomain :

server {
   listen 80;
   listen [::]:80;

   root /var/www/subdomain.domain;
   index index.html

   server_name subdomain.domain.com;
}

Now the probleme is that whenever I want to access to http://www.domain.com or http://subdomain.domain.com, in both case the result is the page that I should obtain for the subdomain.

The new conf file is correctly added to site-enabled folder :

ln -s /etc/nginx/site-available/subdomain.domain.conf /etc/nginx/site-enabled/subdomain.domain.conf

And this is how my DNS records looks like :

domain.com. IN A <server_ip>
www.domain.com. IN A <server_ip>
subdomain.domain.com. IN A <server_ip>
zronn
  • 113
  • 3

1 Answers1

3

You are missing the ; in the index directive, which causes nginx to interpret

index.html

server_name domain.com www.domain.com;

as the content of index directive. Therefore there is no virtual host defined with a server_name, and nginx will use the subdomain virtual host as the catch-all virtual host.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63