caddy-docker-proxy
caddy-docker-proxy copied to clipboard
Can't make it work with multiple ports enabled
Hi,
I am using ApiPlatform 2.6, and would like to use your caddy-docker-proxy in order to have multiple subdomaines on my server. I can't find a way to make things working "nicely", ending up with an error 502. My caddy server I want to reach with the reverse proxy is published on port 4431, so basically I need to route all requests goind to mysubdomain.domain.tld to mysubdomain.domain.tld:4431
It works with these labels :
labels:
caddy: mysubdomain.domain.tld
caddy.reverse_proxy: https://mysubdomain.domain.tld:4431
But I can't success with {{upstreams}} or such, tryed basically everything but always end up with 502 errors or "too many redirects".
Here is the full container in docker-compose :
caddy:
build:
context: api/
target: api_platform_caddy
depends_on:
- php
- client
environment:
SERVER_NAME: mysubdomain.domain.tld
MERCURE_PUBLISHER_JWT_KEY: ${MERCURE_PUBLISHER_JWT_KEY:-!ChangeMe!}
MERCURE_SUBSCRIBER_JWT_KEY: ${MERCURE_SUBSCRIBER_JWT_KEY:-!ChangeMe!}
labels:
caddy: mysubdomain.domain.tld
caddy.reverse_proxy: https://mysubdomain.domain.tld:4431
#caddy.reverse_proxy: "{{upstreams https 4431}}"
restart: unless-stopped
volumes:
- php_socket:/var/run/php
- caddy_data:/data
- caddy_config:/config
ports:
# HTTP
- target: 80
published: 8081
protocol: tcp
# HTTPS
- target: 443
published: 4431
protocol: tcp
# HTTP/3
- target: 443
published: 4431
protocol: udp
networks:
- caddy
Thanks
What you're trying doesn't make sense.
-
You need to bind to ports 80/443 on the host for Automatic HTTPS to work. See https://caddyserver.com/docs/automatic-https
-
You're trying to proxy requests on port 443 (which never reach your container because you bound to port 4431 on the host) to the same domain on port 4431. That looks like you're trying to make it do an infinite loop, you're not actually proxying anything. 🤔 You're meant to proxy to another container.
-
I don't see a php-fpm container in your docker-compose.yml. You need PHP somewhere to run your code. You would use the
pho_fastcgidirective to proxy to your php-fpm container. -
I assume you're making a custom build since you're using Mercure. What does your Dockerfile look like?