How to Install Caddy Web Server on Ubuntu 26.04

Updated on 23 April, 2026
Install and configure Caddy web server on an Ubuntu 26.04 Vultr server with automatic HTTPS certificate provisioning and Caddyfile-based configuration.
How to Install Caddy Web Server on Ubuntu 26.04 header image

Caddy is an open-source web server written in Go that provides automatic HTTPS for all configured domains using Let's Encrypt certificates. It supports static file serving, reverse proxying, and load balancing through a simple configuration syntax called Caddyfile. Caddy handles TLS certificate provisioning and renewal without manual intervention.

This article explains how to install the Caddy web server on an Ubuntu 26.04 server, create a virtual host with automatic HTTPS, and configure firewall rules for HTTP and HTTPS traffic.

Prerequisites

Before you begin, you need to:

Install Caddy

Caddy is not included in the default Ubuntu 26.04 APT repositories. The official Caddy repository provides the latest stable release. The following steps add the repository and install the web server.

  1. Update the APT package index.

    console
    $ sudo apt update
    
  2. Add the Caddy GPG key to the server's keyring.

    console
    $ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
    
  3. Add the Caddy repository to the APT sources.

    console
    $ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
    
  4. Update the package index to include the new repository.

    console
    $ sudo apt update
    
  5. Install Caddy.

    console
    $ sudo apt install caddy -y
    
  6. Confirm the installed Caddy version.

    console
    $ caddy version
    

    Your output should be similar to the one below:

    v2.11.2 h1:iOlpsSiSKqEW+SIXrcZsZ/NO74SzB/ycqqvAIEfIm64=

Manage the Caddy System Service

The caddy systemd service controls the web server process. The following steps enable automatic startup and demonstrate the core service management commands.

  1. Enable Caddy to start automatically at boot time.

    console
    $ sudo systemctl enable caddy
    
  2. Start the Caddy service.

    console
    $ sudo systemctl start caddy
    
  3. Verify that Caddy is active and running.

    console
    $ sudo systemctl status caddy
    

    The output should display active (running), confirming that the Caddy web server is operational.

Set Up Firewall Rules

Uncomplicated Firewall (UFW) is active by default on Ubuntu 26.04. Caddy requires open ports for HTTP and HTTPS traffic. HTTP port 80 is needed for the ACME challenge during automatic certificate provisioning.

  1. Allow HTTP traffic on port 80.

    console
    $ sudo ufw allow 80/tcp
    
  2. Allow HTTPS traffic on port 443.

    console
    $ sudo ufw allow 443/tcp
    

Create a Caddy Virtual Host

Caddy uses a configuration file called Caddyfile located at /etc/caddy/Caddyfile. Each server block defines a virtual host with a domain, document root, and optional directives. Caddy automatically provisions and renews Let's Encrypt SSL certificates for all configured domains.

  1. Create the web root directory for the virtual host.

    console
    $ sudo mkdir -p /var/www/app.example.com
    
  2. Create a sample HTML file in the web root directory.

    console
    $ sudo nano /var/www/app.example.com/index.html
    
  3. Add the following content to the file.

    html
    <html>
    <head>
        <title>Caddy Test Page</title>
    </head>
    <body>
        <h1>Hello World from Caddy</h1>
    </body>
    </html>
    

    Save and close the file.

  4. Back up the default Caddyfile configuration.

    console
    $ sudo mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.default
    
  5. Create a new Caddyfile configuration. Replace app.example.com and admin@example.com with your actual domain and email address.

    console
    $ sudo nano /etc/caddy/Caddyfile
    
  6. Add the following configuration to the file.

    ini
    app.example.com {
        tls admin@example.com
        root * /var/www/app.example.com
        file_server {
            index index.html
        }
        log {
            output file /var/log/caddy/app.example.com.log
            format console
        }
    }
    

    Save and close the file.

    Within the configuration:

    • app.example.com: Defines the virtual host domain. Caddy automatically provisions an SSL certificate for this domain.
    • tls: Specifies the email address for Let's Encrypt certificate registration.
    • root: Sets the document root directory for serving files.
    • file_server: Enables the static file server with index.html as the default file.
    • log: Writes access and error logs to the specified file.
  7. Create the log directory and assign ownership to the Caddy user.

    console
    $ sudo mkdir -p /var/log/caddy
    $ sudo chown -R caddy:caddy /var/log/caddy
    
  8. Format the Caddyfile to ensure consistent indentation and syntax.

    console
    $ sudo caddy fmt --overwrite /etc/caddy/Caddyfile
    
  9. Validate the Caddyfile configuration for errors.

    console
    $ sudo caddy validate --config /etc/caddy/Caddyfile
    

    The output should display Valid configuration.

  10. Reload Caddy to apply the new configuration.

    console
    $ sudo systemctl reload caddy
    

Secure the Caddyfile

Restricting file permissions on the Caddyfile prevents unauthorized modifications to the web server configuration. The following steps assign ownership to the Caddy system user and limit access to the configuration file.

  1. Set the Caddy user as the owner of the configuration directory.

    console
    $ sudo chown -R caddy:caddy /etc/caddy
    
  2. Restrict Caddyfile permissions to the owner only.

    console
    $ sudo chmod 660 /etc/caddy/Caddyfile
    
  3. Access your domain in a web browser to verify the virtual host and automatic HTTPS. Replace app.example.com with your actual domain.

    https://app.example.com

    The browser displays the Hello World from Caddy heading with a valid SSL certificate.

Conclusion

You have installed the Caddy web server on an Ubuntu 26.04 server and configured a virtual host with automatic HTTPS using Let's Encrypt. Caddy handles certificate provisioning and renewal without additional tools or configuration. For more information, refer to the official Caddy documentation.

Comments