skip to Main Content

I created two new projects and deployed it in Digital ocean in same droplet. One is a django and second is a node js project.

The domain is hosted in aws actually, so the first one already works

    sample.maindomain.com (django)
    maindomain.com (nodejs) //currently trying to figure out how route this domain toi nodejs project

Lets say the Digital oceans’ IP address is 167.162.169.224

So the Route 53 is configured like this

     Recordname             Type     Routing         Value/Route traffic to
     sample.maindomain.com  A        Simple          167.162.169.224
     maindomain.com         A        Simple          what should be the value ?

I created two separate files in nginx as reverse-proxy looks like this

//sample.maindomain.com(django)

    server {

           Server_name sample.maindomain.com www.sample.maindomain.com

           location /
             ................


    

// maindomain.com(nodejs)

    server {
           server_name maindomain.com www.maindomain.com
           
           root /home/projectdir/nodejsproject;
        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;
}

}

           ....................
           .......................

So the question is, how can I route the maindomain.com so it will point to the nodejs project nginx configuration hosted in Digital Ocean?

Actually if the project is deployed in Ec2 instance, its more easier to add subdomains by pointing the domain or subdomain to CNAME like ec2-19-192-107-202.eu-central-1.com

2

Answers


  1. Chosen as BEST ANSWER

    I tried to delete and recreate the virtualhosts and restarting the server few times but it did not working.The nginx config is correct and pointing to exact project location but still its pointing to other working project.

    After many googling, I realised that I need to add ssl certificate to the project and install it using certbot https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/

    I am not sure why after adding ssl certificate solves the problem for me


  2. You have to use the same public IP for both hostnames and make your droplet send requests to the right backend based on the Host field of the web requests.

    What is called Virtual Hosting.

    There are a lot of examples how to do that with nginx, this is just a random one: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search