Host a Static Website with Caddy

Published: 2025-05-21

Author: Curby Colvin


How to host a static website with Caddy


What is Caddy?


There are many definitions of a map. I like the following three, from the US.Army, Natinal Geographic, and the University of Texas (Austin).



What is a Static Website


Graphic Representation: Regardless of how the map is drawn, all maps are a graphical representation of some portioin of the earth's surface. What interests me about this is that the graphical representation can be hand drawings, precise maps created with software, and everything in between.


Needed Resources



Create a Linux (Debian) Virtual Machine

There are many options for establishing a server. The popular options are Digital Ocean, Amazon Web Services, Microsoft Azure, and Google Compute Engine.


Each of the CSP's have quality tutorials that cover how to create accounts on those platforms and create virtual machines. HERE is the link to instructions to create and manage a Digital Ocean "Drople". A "Droplet" is Digital Ocean's term for a virtual resource, such as a server.


Note: This example was written with Debian 12x64 as the deployment target.


Install Caddy


Install Caddy on your virtual machine using the instructions found HERE.


Clone the Static Site Repository to the Virtual Machine

At this point, I assume that you have procured a Debian virtual machine and logged into it using Digital Ocean's documentation.


Navigate to var/www/ and run the following command to clone a static site template. Alternatively, you could copy for own html, css, and js files.


Example Caddyfile


    git clone git@gitlab.com:curbyac/static-site-template.git
               


Edit the Caddyfile


Navigate to the etc/caddy directory. The Caddyfile will be in the caddy directory as it is saved there during the Caddy installation. Use Vim or Nano to edit the Caddyfile according to the example shown below.


Example Caddyfile


    # Your domain's A/AAAA DNS records should point to the VM IP
    # Replace ":80" with your domain name

    example.com {
        # Set this path to your site's directory.
        root * /var/www/example
        encode gzip

        # Enable the static file server.
        file_server {
            hide.git
        }

    }

    www.example.com {
        redir https://example.com
    }

    # Refer to the caddy docs for more information.
    # https://caddyserver.com/docs/caddyfile
               

Set up the Domain Name Service


At this point, your last step should be to set up the DNS records with your domain registrar to point your domain name to your server's IP address.


For the setup described in this blog, your DNS setup should include pointing a A(*) record and A(@) record to your severs's IP address.


Good luck!