How To Use Caddy With Your Node.js App for Automatic HTTPS

Using Docker

Louis Petrik
2 min readFeb 29, 2024
Caddy Node.js
Source: Caddy on GitHub

Caddy is a web server famous for providing automatic SSL encryption. I just tried it out and was amazed. It actually works like a charm. After setting everything up as I am describing it in a second, my website instantly had an SSL encryption — No errors or warnings. Here is how to use Caddy as a reverse proxy for a Node.js app (or any other app).

First of all, you need a domain to get working SSL encryption for your web app. Ensure the domain points to your server, e. g., a droplet on DigitalOcean.

Then, make sure you have Docker and Docker Compose installed. In your project folder, create a file docker-compose.yml and copy the following contents into it:

version: '3.8'
services:
app:
image: node:20
volumes:
- .:/app
- /app/node_modules
working_dir: /app
environment:
- NODE_ENV=development
command: bash -c "npm install && npm start"

caddy:
image: caddy:2
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
depends_on:
- app

volumes:
caddy_data:
caddy_config:

Next, we need to create a configuration file for Caddy itself, which is named Caddyfile. Make sure it…

--

--