Using Caddy for local https

1. Output of caddy version:

v2.6.2

2. How I run Caddy:

local network with ip addresses

192.168.2.235:80 ← kiwix http

a. System environment:

lxc in proxmox, ubuntu 20.04
would love to use docker… but unsure how, i always get an error host is already in use…

b. Command:

sudo caddy run --config /opt/caddy/Caddyfile

c. Service/unit/compose file:

Docker:

version: "3.7"
services:
  caddy:
    image: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /opt/containers/caddy/Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config
volumes:
  caddy_data:
  caddy_config:

d. My complete Caddy config:

https://192.168.2.235:10001 {
  reverse_proxy http://192.168.2.235:80
}

3. The problem I’m having:

Hello, i am trying to use caddy to get an ip address within my network to work with ssl. Background: I am using kiwix for offline webpages, however some need an https handler. kiwix itsself is hosted via an lxc container in a docker environment and responds to a local ip address. i cannot use caddy in the same lxc container as port 80 is used by kiwix (and i cannot change it). The idea was to use a second container and run caddy in there. With docker i get an error that the host is already in use.

4. Error messages and/or full log output:

Deployment error

Deployment error
failed to deploy a stack: Removing caddy_caddy_1 Recreating 72a93f5eeec8_caddy_caddy_1 ... Host is already in use by another container e[1Ae[2K Recreating 72a93f5eeec8_caddy_caddy_1 ... e[31merrore[0m e[1B ERROR: for 72a93f5eeec8_caddy_caddy_1 Cannot start service caddy: driver failed programming external connectivity on endpoint caddy_caddy_1 (7be09319dc83077f595399ee975bdf06424dc3072587b64c4419d8e64c82d9f6): Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use ERROR: for caddy Cannot start service caddy: driver failed programming external connectivity on endpoint caddy_caddy_1 (7be09319dc83077f595399ee975bdf06424dc3072587b64c4419d8e64c82d9f6): Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use Encountered errors while bringing up the project. : exit status 1

5. What I already tried:

tried to go without docker:

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf ‘https://dl.cloudsmith.io/public/caddy/stable/gpg.key
curl -1sLf ‘https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt
sudo apt update
sudo apt install caddy
sudo apt install libnss3-tools
2. Caddyfile:
	https://192.168.2.235:10001 {
	   reverse_proxy http://192.168.2.235:80
	}
3. Root.crt to client
	a. Sudo su
	b. cd /root/.local/share/caddy/pki/authorities/local/root.crt
4. sudo caddy run --config /opt/caddy/Caddyfile

problem here: it wants me to run caddy fmt, but when i do nothing happens.

6. Links to relevant resources:

You probably already have something running on port 80. Use this to check any processes already listening there:

sudo lsof -i:80 ## see a specific port such as 80 ##

I find docker is much easier, maybe try that again. You may have some additional config needed running it inside an LXC, I’ve never done that. But you can try this tutorial

1 Like

Just realized you said that kiwix is on :80 and can’t be changed. If that’s the case, you can’t bind the docker container to :80, just comment out that port in your docker compose.

1 Like

hi @jpmiller25 saw your post as well, i think we try to do sth similar. Yeah as i cannot change the port for kiwix, i tried doing caddy in a separate lxc container where 80 is not used.

and within the lxc containers i use docker.

OK, so I’m guessing you have it working from the second LXC container?

@jpmiller25 sorry for the late reply, the docker didnt start and gave me the error above, i will try on the weekend again

This topic was automatically closed after 30 days. New replies are no longer allowed.