Back to Posts

Domain Names

Let’s say you want your domain name to be something different than the IP address of your droplet. Here are the steps for binding a custom domain name to one of your Digital Ocean Droplets.

DNS, or “Domain Name System”, is a naming system that is used to convert a server’s host name into an IP address. DNS is what binds a domain name to a web server that is hosting that domain’s content.


Pre-requisites

The first thing you need to do is purchase your domain name. You can easily get a domain name for $10-15 / year or less, typically you pay for this upfront. I highly recommend Namecheap just for buying domains. Other options are Name.com, 1&1, Register.comand GoDaddy.

If you are going to bundle hosting as well, I suggest using Bluehost.

You will also need to have a Droplet deployed that you want to bind your domain to (this if what we’ve been using all semester).

Once you have your domain name, there are two steps to binding it to a digital ocean droplet:


Point the Nameservers to Digital Ocean

When you purchase your domain, you will be sent credentails to log into the domain registrar’s account management section. Sign in to your Account Manager and look for a section for DNS or Nameservers, typically located inside a section for Domains (or Manage Domains).

Locate the domain that you purchased to bind to your droplet. The domain will be set to default nameservers belonging to your registrar, we want to add custom nameservers. Enter the following nameservers:

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

Note: you may need to add another field in order to have a space for all three nameservers. Be sure to enter all three and then save this.


Connect Digital Ocean to the Domain

Now, log into digitalocean.com and find your Droplets. On the right side of the page, there is a dropdown option for More. Click this and choose Add a domain. Enter the domain that you purchased, and save.


  • Note: it can take some time for the nameservers to update and point to your droplet. I’ve seen this take up to a few hours, usually it’s pretty quick though.


URL Paths

With these instructions, and no changes to your server.js code, here is how you’d find your page:

yourdomain.com:8080/index.html

To simplify this url, you would need to modify your server code. You could change the HTTP portion of the server to load index.html by default.


In order to get rid of the port in the url, you could point port 80 to port 8080 (or whichever port you are opening in your server code). By default, the port number for a Web server is 80 so this is not displayed as part of the url.

In the command line when you are connected to your droplet, enter the following command:

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080


Here’s a guide about How To Point A Domain Name At DigitalOcean Droplet

Digital Ocean has a writeup with more details about this process