lucaslorentz / caddy-docker-proxy

Caddy as a reverse proxy for Docker
MIT License
2.87k stars 168 forks source link

Multiple subdomains, same container, different ports #455

Open pax-k opened 1 year ago

pax-k commented 1 year ago

How can I proxy multiple ports of the same container to different subdomains?

Currently I'm proxying just one of the exposed ports, but I would like to proxy the second port as well, on a different subdomain.

If not possible on a different subdomain, at least on a different path, or the same subdomain but indicating the port.

Anyway https://subdomain-1.myhost.com should always resolve to 1001

ports:
      - mode: host
        protocol: tcp
        published: 1001
        target: 1001
      - mode: host
        protocol: tcp
        published: 1002
        target: 1002
    expose:
      - "1001"
      - "1002"
    networks:
      - caddy
    labels:
      caddy: subdomain-1.myhost.com
      caddy.reverse_proxy: "{{upstreams 1001}}

How could I proxy 1002 without spinning a second container ?

Thank you!

LATER:

I was partially able to proxy it like this:

labels:
      caddy_0: subdomain-1.myhost.com
      caddy_0.reverse_proxy: "{{upstreams 1001}}
      caddy_1: subdomain-2.myhost.com
      caddy_1.reverse_proxy: "{{upstreams 1002}}

But the service running on https://subdomain-2.myhost.com now says "This server only accepts secure HTTPS connections.", even if I'm on HTTPS.

ettoreleandrotognoli commented 1 month ago

I'm using it with minio, and it working fine:

    deploy:
      labels:
        caddy_0: minio.mydomain.com
        caddy_0.reverse_proxy: "{{upstreams 9000}}"
        caddy_1: minio-console.mydomain.com
        caddy_1.reverse_proxy: "{{upstreams 9001}}"

Maybe is something specific of your application @pax-k