Connecting my domain name on digital ocean droplet - node.js

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.

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.

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

What you have to do is create a droplet in DigitalOcean and then add your domain name to the droplet in the Networking tab. You have to add both the non-www and www versions so the domain will be pointed correctly. You have to set the A records for those two to the IP of the droplet that DigitalOcean assigned to it.
Then from your GoDaddy/your domain manager, you have to go to ManageDNS and change the default GoDaddy name servers with those of DigitalOcean. Save it and you are done.
Wait for up to 24 hours and test the domain with check-host.net If all done correctly the domain should point to the servers of DigitalOcean in the city you have selected.

Related

How to point external domain to VPS server

I have a Bluehost VPS account and I need to point my external domain which is purchased from porkbun to my VPS server. After some research, I have changed the A record in the domain registrar to my VPS server IP and changed name servers to Bluehost servers(which are ns1.bluehost.com and ns2.bluehost.com). Currently, when accessing the domain I'm seeing the default Bluehost page, but it does not seem to be connected with the server as it does not display any file I'm updating in the root folder. Is there any step I'm missing? I have tried changing nameservers of the VPS server itself by editing DNS settings in the domain, but any of them does not seem to be working. Any help on this would be highly appreciated.
If you are trying to 'browse' to your VPS server then you would need to add an 'A' record type into the DNS for the domain name.
For example, if you are browsing to 'test.mydomain.com' and your VPS IP Address is '192.186.1.15' then you should add an A Record into the domain zone file with the following detals:
Host Record - test
Points To - 192.168.1.15
These details are taken from the following page:
https://www.bluehost.com/help/article/dns-management-add-edit-or-delete-dns-entries#add

Allow my customer to configure their own domain to the same application

I'm building a shopify-like application. right now when a customer creates a store, he gets some subdomain like https://customer1.shopify-like.com
My Shopify-like frontend application hosts on AWS/ec2 and built with react.js. So, when you visit customer1.shopify-like.com my Nginx(ec2) configuration catches all *.shopify-like.com and load the same react-application (proxy_pass to http://frontend:80, all services up by docker-compose).
and it works fine.
the question is how to allow my customer to configure their own domain as Shopify does.
[docs link][1]
Set up your existing domain to connect to Shopify If you've purchased
your domain through a third party, then you need to edit the following
DNS settings:
Your A record should point to Shopify's IP address, which is
23.227.38.65 Copy
Your www CNAME record should point to shops.myshopify.com Copy.
why Shopify asks you to set CNAME to shops.myshopify.com? what's the proposal?
should I ask my customer to configure CNAME to customer1.shopify-like.com and A Record to my ec2 IP?
if yes, why? because if they just configure the A Record to my ec2 IP. could I catch all requests with Nginx and proxy_pass to my frontend app?
[1]: https://help.shopify.com/en/manual/domains/add-a-domain/using-existing-domains/connecting-domains

Invalid Host header when trying to connect reactjs and domain name

I'm trying to deploy a JS app (back in nodejs, front in reactjs) on a hosting server. I've dockerized everything (back, front and database) and everything works well, I can access my app through the IP address of the server.
Now I'm trying to setup a domain name to point to my app.
I've a Invalid Host header when I try to access from domain name (while still working accessing through server's IP address).
I've tried to add a HOST:mydomain.com to the .env of my reactjs app but I got this error Could not find an open port at mydomain.com
Would love if someone can help me through this :)
Given app works by IP, you can leave config of app as is. Do not add HOST or any other config.
IP to name mapping is done using DNS. So made DNS registration in DNS zone like this
mydomain.com A <IP address of app>
Where A is DNS entry type. Or made request to provider to register A entry type for you.
For testing purposes you may do mapping on any Windows PS using hosts file C:\Windows\System32\drivers\etc\hosts where mapping is done by
<IP address of app> mydomain.com
hosts works on one PC only.
After adding to hosts or to DNS try ping mydomain.com to make sure that name is resolved to correct IP address.
Mapping on web server is done when one web server hosts several different sites on one IP. But when you use Docker it's best to have one Docker container for one service.

Domain not attached to the Cpanel

I registered domain on the WHM and create a new user cpanel with the domain, the domain is added to the cpanel. But when i try to browse the domain name it getting server DNS address could not be found.i updated the name servers with my server name, but nothing changed.
when i try to go through myip/~newuser it going fine to the site file, but with the domain name it's not.
You have a DNS issue in this case. Please check your DNS zone with a tool like intoDns:
https://intodns.com/yourdomain.tld
See if you get any errors there. If you do, then you have issues with your DNS configuration. Be sure that you have create the parent DNS servers for your domain if you want to use the DNS from WHM (the parent DNS servers should point to your WHM server ip).
Try using external services to query your DNS server to see if it actually works (like MXToolBox etc). Or you can use nslookup or dig right from your WHM server by connecting via ssh.

Using a VPS as a DNS Server to Point it to itself

I recently purchased a VPS and I got a free domain (.tk). Now, I wanted to create a domain name server on my VPS, for the .tk domain; this DNS Server should point it to itself.
I followed this URL but in vain. It does not work. How do I setup my VPS so that whenever I enter myname.tk in a browser it resolved to my VPS' IP address and renders the pages?

Resources