I'm following two tutorials (1 and 2) to setup two domains on my server but after many attempts, I can't figure out how to have both domains working and www redirecting to non-www. At the moment, with the same server block files and DNS Records, both work in different ways, I think it could be some cache but I don't know why it is. The server block files are:
server {
listen 80;
listen [::]:80;
server_name domain.com;
root /var/www/domain.com/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
And both have the same DNS Records:
A Record | @ | VPS IP
A Record | www | VPS IP
And the problem is that domains don't work properly.
- "domain1.com" don't work (DNS_PROBE_FINISHED_NXDOMAIN error on Chrome).
- "www.domain1.com" redirects to the default page (the block server that is set as default) and not to the correct one (the one that is in the block server file of domain1)
- "domain2.com" works fine.
- "www.domain2.com" don't work (DNS_PROBE_FINISHED_NXDOMAIN).
I restarted nginx and the VPS but both still work in different ways (as I described).