Hosting 2 domains on one linode using nginx

I have 1 linode instance where I am hosting to websites.

I have an issue where if I do not input www.* then it seems I get redirected to the wrong website.

So the 2 domains I have are sustainablelife.tips and threadcache.com

If I go to www.threadcache.com I am correctly taken to the website. But if I enter threadcache.com then it takes me to sustainablelife.tips.

So here is my nginx server blocks:

threadcache.com:

server {
    server_name threadcache.com www.threadcache.com;

    listen 443 ssl;

    ssl_certificate /etc/letsencrypt/live/threadcache.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/threadcache.com/privkey.pem; # managed by Certbot

    location / {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

sustainablelife.tips:

server {
    server_name sustainablelife.tips www.sustainablelife.tips;

    listen 443 ssl;

    ssl_certificate /etc/letsencrypt/live/sustainablelife.tips-0001/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/sustainablelife.tips-0001/privkey.pem; # managed by Certbot

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Does anyone know why this happens?

Frontend: a Next.js react node application
Backend: PHP Lumen

Let me know if you need any more info.

StayHome StaySafe!

5 Replies

Your DNS records (prob A/AAAA records) are not configured correctly.

I responded to another post recently about this exact same problem for someone else:

https://www.linode.com/community/questions/19542/domaincom-not-working-but-wwwdomaincom-works

— sw

@stevewi hmm flushing the cache? I tried incognito in chrome but same result.
my A records are the same for both domains in linode. And then I supposed that nginx will deal with the redirect to the correct server.

So you are saying its a problem with my computer? I tried the windows flush dns but still its broken. what happens when you go to "threadcache.com"?

I land at http://sustainablelife.tips.

I didn't say that there was anything wrong with your computer. I was merely suggesting that your local DNS cache can sometimes cause problems like the one you're seeing…and that the DNS cache is not the same as the browser cache.

However, now that you've (mostly) eliminated DNS as the source of your issue, the next thing to look at is your web server configuration. I don't know anything about nginx…in the apache world where I live, there are these things called virtual hosts that apache uses to discriminate http traffic for two different web sites on the same server. I have no idea if ngnix has the same/similar thing but that's where I would investigate next.

-- sw

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct