Hello everyone,
Could you please help me?I am currently working with HAProxy in a Docker Compose setup. Here is a snippet of my configuration:
services:
haproxy:
image: haproxy:2.8
container_name: haproxy
ports:
- 80:80
- 443:443
expose:
- '80'
- '443'
volumes:
- ./config/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
- ./config/haproxy/certs/:/usr/local/etc/haproxy/certs/
- ../log:/var/log
depends_on:
- apache-php56
- apache-php74
- apache-php82
networks:
network:
ipv4_address: 10.10.0.2
apache-php56:
user: root
container_name: php56
image: apache-php56
depends_on:
- mariadb
volumes:
- ./config/php56/sites-custom:/etc/apache2/sites-custom
- ./config/php56/sites-enabled:/etc/apache2/sites-enabled
- ./config/php56/hosts:/etc/hosts
- ../sites:/var/www/sites
- ../data:/data
- ../log:/var/log
networks:
network:
ipv4_address: 10.10.0.3
In the HAProxy configuration file, I have set up the following rules:
acl is_apispfr hdr(host) -i api-dev.fr
use_backend php56_backend if is_apispfr
backend php56_backend
server apache-php56 apache-php56:80
This works perfectly.I currently have another Docker Compose setup:
text
services:
php:
image: ${IMAGES_PREFIX:-}app-php
restart: unless-stopped
environment:
SERVER_NAME: ${SERVER_NAME:-api-gateway.localhost}, php:80
TRUSTED_PROXIES: ${TRUSTED_PROXIES:-127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
TRUSTED_HOSTS: ${TRUSTED_HOSTS:-^${SERVER_NAME:-example\.com|api-gateway\.localhost}|php$}
volumes:
- caddy_data:/data
- caddy_config:/config
networks:
pap_dev_network:
ipv4_address: 10.10.0.12
ports:
# HTTP
- target: 80
published: ${HTTP_PORT:-85}
protocol: tcp
# HTTPS
- target: 443
published: ${HTTPS_PORT:-450}
protocol: tcp
networks:
pap_dev_network:
external: true
volumes:
caddy_data:
caddy_config:
When I use https://api-gateway.localhost:450
, everything works correctly, and I can access Caddy.My question is how can I configure HAProxy to redirect https://api-gateway.localhost
to https://api-gateway.localhost:450
, so that HAProxy forwards the requests to the appropriate service?Thank you for your assistance!