How to Install Caddy on Debian Latest

Caddy is a web server designed to work in HTTP/2, HTTP/3 and HTTPS environments. It's easy to use, has modern features and is performant. In this tutorial, we will guide you through the process of installing Caddy on Debian Latest.

Step 1: Update the System

Before installing Caddy, we need to make sure that our system is up to date. Run the following command to update the package lists on your system:

sudo apt update

After updating the package lists, run the following command to upgrade your existing packages:

sudo apt upgrade

Step 2: Download Caddy

The first step in installing Caddy is to download the script from the official website. Run the following command to download Caddy:

curl https://getcaddy.com | bash -s personal http.filter,http.forwardproxy,tls.dns.cloudflare

This command will download and install Caddy in your /usr/local/bin directory.

Step 3: Create a Caddy Configuration

Now that Caddy is installed on your system, you will need to create a configuration file. In this example, we will use the default configuration file that comes with Caddy.

Create a new directory for your Caddy configuration file and navigate to it:

sudo mkdir /etc/caddy
cd /etc/caddy

Create a new file called Caddyfile in the current directory:

sudo nano Caddyfile

Add the following example content to this file:

example.com {
    root /var/www/example.com
    tls email@example.com
    log /var/log/caddy/example.log
}

This configuration file sets up a HTTPS site for example.com, uses /var/www/example.com as the root directory for files and logs requests to /var/log/caddy/example.log.

Save and close the file by pressing CTRL + X, then Y, and then Enter.

Step 4: Test the Configuration

Before starting the Caddy server, you should check if your configuration file is valid. Use the following command to test your configuration file:

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

This command should output a message similar to the following:

Valid configuration with no warning or error.

If there are any issues with the configuration file, Caddy will output an error message indicating what the issues are.

Step 5: Start Caddy

Now that the configuration file is validated, it's time to start Caddy. Use the following command to start the server:

sudo caddy run --config /etc/caddy/Caddyfile

This command will start the Caddy server using the configuration file you just created.

You can now access your website at https://example.com in your web browser. If you get any errors, check the error logs in /var/log/caddy/ for more information.

Conclusion

In this tutorial, we showed you how to install Caddy on Debian Latest. After installation, you should be able to easily create new configurations and serve websites using Caddy.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!