lucaslorentz / caddy-docker-proxy

Caddy as a reverse proxy for Docker
MIT License
2.84k stars 169 forks source link

New to caddy docker proxy - Can't manage to get Vikunja to work #447

Open LeVraiRoiDHyrule opened 1 year ago

LeVraiRoiDHyrule commented 1 year ago

Hi,

I'm new to caddy docker proxy and I find it wonderful so far. I'm trying to get Vikunja to be reverse proxied by caddy docker proxy. From Vikunja docs, here the configuration to achieve:

vikunja.example.com {
    reverse_proxy /api/* api:3456
    reverse_proxy /.well-known/* api:3456
    reverse_proxy /dav/* api:3456
    reverse_proxy frontend:80
}

I can't figure out what will be the equivalent with labels. I tried this:

    labels:
      caddy: vikunja.mydomain.com
      caddy.1_reverse_proxy: frontend:80
      caddy.2_reverse_proxy: /api/* api:3456
      caddy.3_reverse_proxy: /.well-known/* api:3456
      caddy.4_reverse_proxy: /dav/* api:3456

and this:

    labels:
      caddy: vikunja.mydomain.com
      caddy.reverse_proxy: frontend:80
      caddy.1_handle_path: /api/*
      caddy.1_handle_path.reverse_proxy: api:3456
      caddy.2_handle_path: /.well-known/*
      caddy.2_handle_path.reverse_proxy: api:3456
      caddy.3_handle_path: /dav/*
      caddy.3_handle_path.reverse_proxy: api:3456

But none of them seem to be working. For both of these, the frontend is accessible but the api is not. Could someone help me to find the correct syntax ?

Thanks in advance for your help and have a great day

francislavoie commented 1 year ago

FWIW, that Caddyfile could be simplified to this:

vikunja.example.com {
    @api path /api/* /.well-known/* /dav/*
    reverse_proxy @api api:3456

    reverse_proxy frontend:80
}

You'll need to elaborate on what you mean by "none of them seem to be working". We need to see logs. Check your /config volume, CDP writes the output Caddyfile in there, so you can validate that the labels were transformed to the config you expect.

mawoka-myblock commented 9 months ago

The solution with the hint form @francislavoie

services:
  api:
    image: vikunja/api
[... snip ...]
    labels:
      caddy: placeholder.doesnotexist
      caddy.@vikunja_backend.path: '/api/* /.well-known/* /dav/*'
      caddy.reverse_proxy: '@vikunja_backend "{{upstreams 3456}}"'
    networks:
      - caddy
      - vik
  redis:
    image: redis
    restart: unless-stopped
    networks:
      - vik
  db:
    image: postgres:13
[... snip ...]
    networks:
      - vik
  frontend:
    image: vikunja/frontend
    environment:
      VIKUNJA_API_URL: https://placeholder.doesnotexist/api/v1
    restart: unless-stopped
    labels:
      caddy: placeholder.doesnotexist
      caddy.reverse_proxy: "{{upstreams 80}}"
    networks:
      - caddy
      - vik

networks:
  caddy:
    external: true
  vik:
    external: false