Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting my domain name on digital ocean droplet

I created a small hello world node app, then i hosted the app on digital ocean droplet, after that i can access my application on http://my_public_ip:3000

Felt happy 😍

Then i bought a domain name called helloworld.tk free domain from freenom.com After that i install nginx as a webserver in my droplet then i added a reverse proxy code in /etc/nginx/sites-enable/default

My code looks like:

   server {
   listen 80;
   server_name helloworld.tk

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

After that i went to domain management panel in my freenom.com and set url forwarding to http://my_public_ip

So if i enter my domain name helloworld.tk in browser my node app successfully works 🤩 but wait what 🤔 my ip address is showing on left side below corner on chrome and if i refresh the page multiple times i get

   402 Too many request error page on nginx

So i deleted my url forwarding and in my domain management panel instead of url forwarding i set my nameservers like this ns1.digitalocean.com bla.bla.bla...

Then i added my domain in my digitalocean panel. Now yes everything is working perfect.

If i hit my url no ip address is showing, also no too many request errors 😌

My node app successfully getting executed!

Wait i am a beginner for hosting node app, so i need help whether it is correct good setup for nodeapp on production?

What is the difference between url forwarding and nameservers? Whether my nginx reverse proxy code is correct? is my reverse proxy working correctly?

NOTE: I used pm2 for running node app on background.

like image 561
Mohamed Sameer Avatar asked Sep 29 '18 14:09

Mohamed Sameer


2 Answers

First, remove the forwarding and you need to change the nameservers of the domain in your domain DNS management if your domain is somewhere other than DigitalOcean

Add below nameservers:

ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com

Now check if they are propagating by using whatsmydns.net (Enter your IP and change click on A and select NS and click Search)

Once they are propagating, add the domain to your DigitalOcean account.

Go to your DigitalOcean Dashboard and click on Networking.

Add a domain and click Save.

Then Edit the domain and add the Droplet to the Domain and save.

Now click on the domain name and an A record which points to your droplet.

Hope this will resolve your issue.

like image 85
Sushma Gangolu Avatar answered Sep 30 '22 08:09

Sushma Gangolu


Go back to your DNS domain registrar ( freenom.com ) and remove mention of digitalocean nameservers and put back its own default frenom.com nameservers ... also on freenom.com assure you have defined a Type A record to point to your machine's external IP address

Your nginx config looks OK

this should work ... now had you defined digitalocean nameservers in your freecon.com registrar you would have then needed to go to https://cloud.digitalocean.com/networking/ and set up your Type A record there ... its critical to know the location of your nameservers determines where your Type A record must live

like image 40
Scott Stensland Avatar answered Sep 30 '22 08:09

Scott Stensland