Setup Caddy server

Self hosted PayloadCMS and PostgreSQL website on Docker

3 min read

Published Jun 17 2025, updated Jun 19 2025


10
0
0
0

CaddyDockerGitHub ActionsJavascriptNextJSPayloadCMSPortainerTailscaleUbuntuUFW

We are going to install Caddy directly on the server and forward all requests to the servers localhost of the published ports. Caddy will handle all incoming traffic on 443, automatically setup SSL certificates and pass http traffic to the docker containers. Technically you can opt to install as a docker container and for the most part this works fine, however if you need things like self hosted analytics where the users original IP address is required for deriving the country and region of users etc. then you run in to problems as the referred IP will be of the docker internal IP, so I find it easier hosting Caddy outside of docker. If you don't need anything where the users IP details are required, then you can run in a docker container and use the <servicename>:<containersinternalportnumber> as the url to refer to, instead of <localhost>:<publishedportnumber> which we will be doing below, and that means you also don't actually need to publish ports for the web server and registry as it will be handled on the internal docker network.


Update the package index:

sudo apt update

Make sure apt-transport-https and curl are installed:

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl

Import Caddy’s official GPG key:

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

Add the Caddy repository:

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

Update package index again:

sudo apt update

Install Caddy:

sudo apt install caddy

You can verify the install by running:

caddy version

Starts the Caddy service immediately:

sudo systemctl start caddy

Enables Caddy to start automatically on boot:

sudo systemctl enable caddy

Shows the current status of the Caddy service:

sudo systemctl status caddy

All reverse proxy rules etc are defined in the CaddyConfig file located /etc/caddy/Caddyfile.


You need to add DNS entry for a domain that you want to point to the docker registry created in the last section.

eg. if you would like to use the subdomain registry.mydomainname.com to access it, set an A record on your mydomainname.com for registry.mydomainname.com to point to your public IP address. This needs doing on your domain registrar website.



Add a reverse proxy for the docker registry:

/etc/caddy/Caddyfile

registry.mydomainname.com {
        reverse_proxy localhost:5000
}

You can clear out any other code in that file and just put the code you need. Anything with a # at the start is a comment line and ignored.

What the above is saying is anything that comes in on port 443, which Caddy is listening to on the public IP, Caddy will automatically obtain and sort out SSL certificates, and pass all traffic destined for registry.mydomainname.com over https, through to localhost:5000 which is the published registry docker container.


Reload the Caddy Config, without server downtime, after config changes:

sudo systemctl reload caddy

Note: for a full start and stop of the server, but not required here:

sudo systemctl restart caddy

You can test thats worked by logging in do the registry via docker on your main computer:

docker login registry.mydomainname.com

It will ask you for your username and password which you setup in the last section, if it is successful then its all working as expected.


Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact