I started this project as a way to learn new skills with modern web technology. This post walks you through how to set up a new domain and get it pointing to your new host. I’m going to assume you have a semi-technical background.
I would recommend setting up your hosting solution first, as you need something to point to once your domain is set up. I chose AWS EC2 as I wanted something cloud based and fast to spin up that allowed me to experiment with Docker. It’s free to try and seemed like it would support what I wanted to do. Bare in mind that this ties you to the Amazon infrastructure, which I planned on mitigating by using Docker so that my implementation is transferable.
Step 1: Set up AWS EC2 with Elastic IP
Amazon offers a hosting service called EC2 that is initially free, but then moves to a charge-for-usage model after you exhaust your allocated CPU time credit. Each time an EC2 instance is destroyed and created, it is assigned a new address. You need to create an Elastic IP to associate with your EC2 instance. This will become your public facing IP address that routes traffic to your new EC2 host.
- Sign up for an account here and navigate to the AWS console.
- Go to the EC2 panel and choose Launch Instance to start the wizard.
- Work your way through the wizard, reading all the info carefully to understand associated costs. I chose a t2.micro instance of Amazon Linux AMI 2018.03.0 (HVM) as it is free, has native Docker support, and I am relatively comfortable using a Linux distribution.
- When you get to the Security Group page, add the following rules to accept requests for Web traffic, SSL, SSH and Ping. You can then launch your instance.
- Go to the Elastic IP page and click on the button that says Allocate new address. Be aware that you are charged for addresses that you don’t use, so make sure you have an instance ready to go when you are doing this.
- Once your new Elastic IP is created, associate it with your EC2 instance by selecting it and choosing Associate address from the Actions dropdown. You will then be shown a page where you can select the instance you want to bind to your new address.
7. You can check this has worked correctly by going back into your EC2 console and looking at the details under the description tab. Make note of your Public DNS and Public IP as you will need them later. You should also now be able to ping your Elastic IP and get a response, proving that your new server is reachable from the internet.
Step 2: Domain Registration and Forwarding
I selected Namecheap for the domain registration after some Reddit research. It was a balance between cost, reliability and reputation. There were also other factors including being based in the UK, and only required a .co.uk domain. You should do your own research, as there may be a better alternative for you.
- Choose your domain name and register it with Namecheap.
- Go to your Dashboard and under Domain List you should have a Manage option next to your newly created domain.
- Navigate to Advanced DNS in horizontal menu and create the following:
The A record points to you public Elastic IP, and the CNAME records point to the public DNS server you made a note of earlier. I have 2 CNAME records, for the subdomain www and a wildcard to catch everything else.
- Save this and wait a few moments for it to propagate. You should the be able to ping your domain and see it resolve back to your EC2 instance.
Setting up a domain pointing to a cloud based hosting solution is relatively straight forward. The majority of the time will be spent reading and understanding which options are required to meet your goals. There’s no need to go for a top of the range solution immediately if you are just starting out, and conversely you shouldn’t cheap out if you know you are going to need a bit of robustness and grunt.
Finally, if you have no idea where to start – ask a professional.