DEV Community

Eduardo Issao Ito
Eduardo Issao Ito

Posted on • Updated on

Caddy as a simple "api gateway" with SSL

What is Caddy

Caddy is an open source web server with automatic HTTPS.
We will use it to create a simple "api gateway".

Preparing sample services

Start sample services

docker container run -d -p 5000:5000 proclaim/crp-app1
docker container run -d -p 8800:8800 proclaim/crp-app2

Test services

curl http://localhost:5000/api/member
curl http://localhost:8800/api/food

Configuring local caddy

mkdir ~/api-gateway
cd ~/api-gateway

Obtain machine information


hostname -I 

Create the SSL certificate for this machine

openssl req -nodes -new -x509 -keyout server.key -out server.cert \
-subj "/C=AU/ST=Some-State/L=City/O=Company Name/OU=Department/"

Create Caddyfile configuration {
    tls /etc/server.cert /etc/server.key
    proxy /api/member
    proxy /api/food

Start caddy server

docker run -d \
  -p 443:2015 \
  -v $HOME/api-gateway/Caddyfile:/etc/Caddyfile \
  -v $HOME/api-gateway/server.key:/etc/server.key \
  -v $HOME/api-gateway/server.cert:/etc/server.cert \

Test https services through caddy

curl -k
curl -k


Top comments (0)