Skip to content
Go back

Using Caddy Server with VPS for Automatic HTTPS

Using Caddy Server with VPS for Automatic HTTPS

Introduction

Caddy is a modern web server with automatic TLS, making HTTPS setup trivial. This guide covers installing Caddy on a VPS and configuring reverse proxies.

Prerequisites

Step 1: Install Caddy

# Install via official repository
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo apt-key add -
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

Step 2: Basic Caddyfile

Edit /etc/caddy/Caddyfile:

example.com {
  reverse_proxy localhost:3000
}

Step 3: Test Configuration

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

Step 4: Configure Multiple Sites

example.com, www.example.com {
  reverse_proxy localhost:3000
}

api.example.com {
  reverse_proxy localhost:4000
}

Caddy obtains and renews certificates automatically.

Step 5: Logging and Monitoring

By default, Caddy logs to systemd. To customize, configure log in Caddyfile:

example.com {
  log {
    output file /var/log/caddy/example.access.log
    format console
  }
  reverse_proxy localhost:3000
}

Summary

Caddy’s automatic HTTPS and simple configuration make it ideal for VPS-hosted applications. Define sites in the Caddyfile, and Caddy handles certificates and proxying seamlessly.


Share this post on:

Previous Post
Building a Custom Strapi v5 Plugin for Admin Panel
Next Post
Setting Up Coolify for Self-Hosted Deployments