Setting Up Caddy on Ubuntu EC2: A Guide to Installing and Mapping Domain Names with GoDaddy.

Shrihari Haridas
4 min readJan 27, 2024

--

Credit: Welcome — Caddy Documentation (caddyserver.com)

What is Caddy.?

Caddy is an open-source web server that is designed to be simple, efficient, and secure. It is written in Go programming language and is known for its ease of use, automatic HTTPS support, and extensibility. Caddy’s primary goal is to make it easy for developers to set up and configure web servers without the need for complex configurations.

  1. Log in to your AWS account, launch an Ubuntu instance, and access it.

2. Before accessing the instance, go to your domain name provider — in my case, I am using GoDaddy, where you purchased the domain name.

3. Next, click on your main domain. Once opened, you will see the ‘DNS’ option, so click on it.

4. Proceed by clicking on ‘Add New Record’ and choose either ‘A’ type or ‘CNAME’.

5. Select your subdomain name — in my case, I chose ‘blog.’ Then, go to AWS, copy your instance’s ‘Public IP,’ and paste it in the ‘Values’ section. Click on save; the changes will reflect after 1 hour.

6. Connect to your instance, and install Docker and Docker-compose since we will be hosting our website inside Docker on port 82.

sudo apt-get update
sudo apt-get install docker.io -y
sudo apt-get install docker-compose -y

7. then install caddy on your machine

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

8. After using the command, Caddy is installed on your machine. To check if Caddy is running, use the following command:

systemctl status caddy

9. Open a web browser and enter your public IP followed by port 80.

10. Now, let’s map our domain to this IP. To edit the ‘Caddyfile,’ navigate to the following location where you will find the Caddy file.

cd /etc/caddy

11. Next, create a ‘docker-compose.yml’ file and add the Docker configuration below, ensuring to open port 82.

version: '3'

services:
webserver:
image: nginx
ports:
- "82:80"
volumes:
- ./path/to/your/index.html:/usr/share/nginx/html/index.html

12. Now, if you open it in the browser, you should see it running on the IP address.

13. Return to the ‘CaddyFile’ location, make the necessary edits, and save the file.

your.domain.com {
reverse_proxy localhost:your_node_app_port
}

14. Now, before running Caddy, perform a ‘DNS lookup’ to check if your domain is mapped to your IP. In my case, it has been updated.

15. Now, run Caddy again with the following command:

caddy run

Summary:

In summary, this guide takes you through the process of setting up a Caddy server on an Ubuntu EC2 instance, mapping a domain with GoDaddy, and hosting a website using Docker on port 82. Starting from AWS instance creation to DNS configuration, Docker installation, and Caddyfile editing, the steps ensure a straightforward connection between the domain and the server. After running Caddy and verifying DNS updates, users can successfully deploy a website on their Ubuntu EC2 instance.

--

--

Shrihari Haridas
Shrihari Haridas

Written by Shrihari Haridas

Hello everyone, I am Shrihari Haridas I am a Cloud & DevOps Engineer, I work with most of DevOps Tools like, Jenkins, Git, Docker, etc.!& for Cloud AWS

No responses yet