DEV Community

Mohamed Sameer
Mohamed Sameer

Posted on

Connecting my domain name on digital ocean droplet

Hey guys!

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;
   }
  }
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

Discussion (1)

Collapse
chiefnoah profile image
Noah Pederson

For starters, your nginx configuration was correct and was behaving in an expected way. When you specify a hostname in the server_name field, it will only handle requests where the Host header is set to that hostname. To have nginx use the proxy_pass for everything, use default_server instead of the hostname:

server {
   listen 80;
   server_name default_server;

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

Remember to restart nginx after updating the configuration :)