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".

https://caddyserver.com/

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
ziba-Aspire-A515-51G.adzubla.net

hostname -I
192.168.59.50 

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/CN=ziba-Aspire-A515-51G.adzubla.net"

Create Caddyfile configuration

ziba-Aspire-A515-51G.adzubla.net {
    tls /etc/server.cert /etc/server.key
    proxy /api/member  192.168.59.50:5000
    proxy /api/food    192.168.59.50:8800
}

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 \
  abiosoft/caddy:1.0.3-no-stats

Test https services through caddy

curl -k https://ziba-aspire-a515-51g.adzubla.net/api/member
curl -k https://ziba-aspire-a515-51g.adzubla.net/api/food

Reference: https://medium.com/bumps-from-a-little-front-end-programmer/caddy-reverse-proxy-tutorial-faa2ce22a9c6

Top comments (0)