3

I have two different domain names with completely different websites. This is how my nginx configuration looks like:

server {
    listen 80;

    server_name domainnameone.com;

    location / {
        proxy_pass http://localhost:3000;
    }
}

server {
    listen 80;

    server_name domainnametwo.com;

    location / {
        proxy_pass http://localhost:9000;
    }
}

The first website resolves well for the IP address. For the second domain if I go to ipaddress:9000 I get the file that is supposed to correspond with website two as desired. I'm trying to set route53 to display the website2 when I go to www.domainnametwo.com, currently it's displaing the first website. I've created a new hosted zone for the second website and pointed the domain registrar to the values in the hostedzone2. I can only get the second website to show if I specify the port on www.domainnametwo.com:9000. I must specify that I am using cloudfront for the first website but I don't think that should interfere.

Is this a nginx or a route53 issue?

Dong
  • 135
  • 5
  • Not enough for an answer, but remember that your configuration could be correct, and you're just getting a cached version of your page. It can help to test in a place where your browser couldn't POSSIBLY cache an old version of these addresses, or disable caching temporarily in your browser. – cawwot Jul 20 '20 at 18:38

3 Answers3

3

This isn't a Route53 problem. So long as your request for a domain name is mapped to the correct IP then Route53 has done its job. You don't even need different ports, Server Name Indication (SNI) lets you have as many IPs as you like on the same IP for http or https.

I suspect your issue is with your Nginx or downstream config. That config you pasted above looks about right to me, but I haven't done much with Nginx in a while.

Tim
  • 31,888
  • 7
  • 52
  • 78
3

Most likely this could be nginx issue, did you restarted nginx after making changes to config?

Just to make sure, you not using the same dns record as you using for first site which would be a CNAME record pointing to cloudfront.

Update your nginx server block to include both the name (naked domain + your www as you trying to access using in the example you shared:

 server {
    listen 80;

    server_name domainnameone.com www.domainnameone.com;

    location / {
        proxy_pass http://localhost:3000;
    }
}

server {
    listen 80;

    server_name domainnametwo.com www.domainnametwo.com;

    location / {
        proxy_pass http://localhost:9000;
    }
}
Khushal
  • 176
  • 3
  • Did restart and have different dns configuration. I'm pretty sure I need to do something different with the nginx configuration file but I don't know how to write it. – Dong Jul 20 '20 at 02:03
  • Udpated my answer to include the nginx config changes as you have only mention of naked domain in server block, but you using different name i.e. www.domainnametwo.com to access. – Khushal Jul 20 '20 at 02:19
3

You need to create a server block in nginx, or use an existing one, which contains a server_name matching the hostname you are trying to use. You have twice used hostnames that are not shown in the nginx configuration you posted, so you need to add them.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972