Cantech Knowledge Base

Your Go-To Hosting Resource

How to Install Caddy Webserver on Ubuntu 24.04?

Caddy web server is fast, modern, and easy to work with. It is a great open-source option, and it comes with features like automatic HTTPS. So, you don’t have to worry about setting up SSL certificates manually.

Moreover, it is written in the Go language and is built in such a way that you can use it not just for serving static websites but also for reverse proxy and load balancing. Caddy can handle everything from a small site or running microservices smartly.

This article will show how to install and run the Caddy web server on Ubuntu 24.04. This version of Ubuntu is fresh and stable, so it is a great choice for hosting your web applications.

What You Need Before Starting

Make sure you have got the following things sorted:

  • You need an Ubuntu 24.04 server ready to go.
  • Your domain name should be pointing to your server’s IP address using an A record.
  • Use SSH to connect to the server.
  • Make sure you are not working as root. Create a user with sudo rights and switch to it.

Installing Caddy on Ubuntu 24.04

Caddy does not come by default in Ubuntu software sources, so you will need to add its official repository manually. Follow the steps below for the same –

Add the GPG Key

You need to fetch and save Caddy’s security key. This helps Ubuntu confirm the downloaded package is legit.

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg

Add the Caddy Repo to APT

The key is now added. Next, tell Ubuntu where to get Caddy from:

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list

Update and Install

Refresh your packages and get Caddy installed.

sudo apt update
sudo apt install caddy

Check the version and make sure it is installed.

caddy -v

You should see something like:

v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=

Allow Caddy Through the Firewall

Caddy needs access to HTTP port (80), so allow it with –

sudo ufw allow 80
sudo ufw reload

Now, visit your server IP in a browser and make sure you see the default Caddy welcome page.

Manage Caddy as a Service

Caddy runs as a system service on Linux. Let’s make sure it starts automatically and runs properly. You should see something like “active (running)” in the output. That means it is working fine.

sudo systemctl enable caddy
sudo systemctl start caddy
sudo systemctl status caddy

Set Up a Website with Caddy (Virtual Host)

Now host your own site using Caddy. Let’s say your domain is example.com.

Create Your Site Folder

  • Make a folder where your website files will live.
    sudo mkdir -p /var/www/example.com
  • Now create a simple HTML page:
    sudo nano /var/www/example.com/index.html
  • Paste this content inside:
    <html>
    <head>
    <title>Greetings from Vultr!</title>
    </head>
    <body>
    <h1 align="center">Hello World!, Greetings from Vultr</h1>
    </body>
    </html>
  • Save and exit.

Step 2: Configure Caddyfile

  • Go to the directory where Caddy looks for its configuration.
    cd /etc/caddy/
  • Back up the default config:
    sudo mv Caddyfile Caddyfile.default
  • Now create a fresh Caddyfile:
    sudo nano Caddyfile
  • Add this configuration:
    example.com {
    tls [email protected]
    root * /var/www/example.com
    file_server {
    index index.html
    }
    log {
    output file /var/log/caddy/example.log
    format console
    }
    }
  • This setup does the following:
  • Uses your domain name as the server name.
  • Sets up HTTPS using Let’s Encrypt with your email.
  • Serves files from your website folder.
  • Log access details in a file.

Step 3: Check and Reload

Now test if the config is correct:

caddy validate

If no error shows up, go ahead and reload Caddy:

sudo caddy reload

Lock Down the Caddyfile

You don’t want others on your server to mess with your configuration.
Change ownership and permissions:

sudo chown -R caddy:caddy /etc/caddy
sudo chmod 660 /etc/caddy/Caddyfile

You can double-check:

ls -l /etc/caddy/

Your Caddyfile should show permissions like -rw-rw—-.

Open More Firewall Ports

Caddy uses port 443 for HTTPS. Let’s allow that too.

  • Check if firewall is active:
    sudo ufw status
  • Turn it on and make sure SSH stays open:
    sudo ufw allow 22 && sudo ufw enable

    Now allow HTTPS:

    sudo ufw allow 443
    sudo ufw reload

    Lastly, visit https://example.com and see your site live with SSL.

Conclusion

Your Caddy web server is now set up on Ubuntu 24.04. You created your own virtual host and served a simple HTML website securely over HTTPS. Caddy makes things easy with its automatic configuration and clean setup style.

May 26, 2025