Can't figure out Caddy + Docker reverse proxy

1. The problem I’m having:

I’m trying to set up Caddy as a reverse proxy in a Docker environment. After starting the containers I see no errors (container starts successfully) and one of the services I’m trying to access works (Vaultwarden), the other errors out.

2. Error message.

   "level": "error",
   "ts": 1699874409.0697393,
   "logger": "http.log.error",
   "msg": "dial tcp connect: connection refused",
   "request": {
      "remote_ip": "",
      "remote_port": "46364",
      "client_ip": "",
      "proto": "HTTP/2.0",
      "method": "GET",
      "host": "",
      "uri": "/",
      "headers": {
         "Accept": [
         "Accept-Encoding": [
            "gzip, deflate, br"
         "Sec-Fetch-Dest": [
         "Sec-Fetch-Mode": [
         "Sec-Fetch-User": [
         "User-Agent": [
            "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0"
         "Accept-Language": [
         "Upgrade-Insecure-Requests": [
         "Sec-Fetch-Site": [
         "Te": [
      "tls": {
         "resumed": false,
         "version": 772,
         "cipher_suite": 4865,
         "proto": "h2",
         "server_name": ""
   "duration": 0.0014571,
   "status": 502,
   "err_id": "sq25yrguc",
   "err_trace": "reverseproxy.statusError (reverseproxy.go:1265)"

I use Docker compose file on a Rocky 9 server. Here’s the Caddyfile: {
    reverse_proxy ghostsite
} {
    reverse_proxy vaultwarden
} works, errors out.

3. Caddy version:


4. How I installed and ran Caddy:

  • it’s installed via Docker compose. Here’s the compose.yaml file:
    image: caddy:latest
    container_name: caddy
    restart: unless-stopped
      - NET_ADMIN
      - "80:80"
      - "443:443"
      - "443:443/udp"
      - $PWD/Caddyfile:/etc/caddy/Caddyfile:ro
      - $PWD/site:/srv
      - $PWD/caddy_data:/data
      - $PWD/caddy_config:/config
      - robisznet

    image: ghost:latest
    container_name: ghostsite
    restart: always
      database__client: sqlite3
      database__connection__filename: content/data/ghost.db
      NODE_ENV: production
      mail__transport: SMTP
      mail__options__port: 2525 
      mail__options__service: SMTP2Go
      mail__options__auth__pass: /run/secrets/mail_password
      - ~/new/ghost:/var/lib/ghost/content:z
      - robisznet
      - mail_password
      - caddy

    image: vaultwarden/server:latest
    container_name: vaultwarden
    restart: always
      WEBSOCKET_ENABLED: "true"  # Enable WebSocket notifications.
      SHOW_PASSWORD_HINT: "false"
      DOMAIN: ""
      SIGNUPS_ALLOWED: "false"
      SMTP_HOST: ""
      SMTP_FROM: ""
      SMTP_PORT: "465"
      SMTP_SECURITY: "force_tls"
      SMTP_USERNAME: "testowysite"
      SMTP_PASSWORD: /run/secrets/vault_mail_pass
      - ./vw-data:/data
      - robisznet
      - vault_mail_pass
      - caddy


    file: ./.ENV/mail.txt
    file: ./.ENV/vault_mail.txt

a. System environment:

It’s running Docker on Rocky 9.

I’ve tried disabling SELinux and UFW, but that didn’t help.

All suggestions are greatly appreciated - I’m inexperienced when it comes to setting up proxies.

Checked whether containers indeed share the same network with:

docker network inspect -f '{{range .Containers}}{{.Name}} {{end}}' testowe_robisznet

and I got:

caddy ghostsite vaultwarden

When proxying, you need to use the port number that the service actually listens on.

For example, see the docs on which explains that the default port is 2368, so you should use reverse_proxy ghostsite:2368 instead.

1 Like

thank you Francis!
Ok, so now I have Ghost working with the following entry in Caddyfile: {
	reverse_proxy ghostsite:2368 {
		header_up Host {host}

Let’s say I have more Ghost blogs, each in its own container - does every one need to have a different port? I assumed not, as I thought it’s being handled by the Docker’s networking stack (each container has its own address).

How about several Wordpress sites? Would it be something like: {
	reverse_proxy wp1:80
} {
	reverse_proxy wp2:80
} {
	reverse_proxy wp3:80

Ans so on? How does https works in this scenario?

Do I have to set up “ports” section of the compose.yml file? More specifically - do I need to bind container port to some specific host one? If yes - should the port be different for each service (container / docker compose entry)?

I know it is probably pretty basic, RTFM kind of stuff - thus I appreciate your answer even more.
I’m a bit overwhelmed as I’m trying to learn to many things at once.

Remove this; you don’t need it, Caddy already passes through the Host as-is.

If they’re all the same base image, then they’ll all be using the same port. They’re isolated from eachother.

Caddy issues certs for each domain you list in your config.

All you need is this, which you already have:

1 Like

Ok, so possibly the last thing to figure out. If I decide to have multiple Wordpress instances how do I deal with mouting /var/www/html ?

So with single Wordpress the container with it has:

      - $PWD/php.ini:/usr/local/etc/php/conf.d/custom.ini
      - $PWD/wordpress:/var/www/html

and the one with Caddy:

      - $PWD/wordpress:/var/www/html

With following entry in Caddyfile: {
        root * /var/www/html
        php_fastcgi wordpress:9000

– thus I’m not sure how I add another one.

If you use a wordpress apache container, you can avoid that entirely by simply proxying to it.

But if you use php-fpm, yes that is something to resolve.

Mount it to separate directories in Caddy like /srv/wordpress1 and /srv/wordpress2, set those as your root. Then in php_fastcgi use the root option to set php-fpm’s root to /var/www/html. That way Caddy will read files from /srv and such, and when it tells php-fpm to run the PHP scripts it will read from /var/www/html in its own container.

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