From 4cfd6443b924c881abf497721c87ecf60da7ff23 Mon Sep 17 00:00:00 2001 From: chungyan5 Date: Fri, 26 Jun 2026 14:43:55 +0800 Subject: [PATCH] 1) Fix router/service name collision when same container serves multiple domains --- Design_Doc/DevProc.md | 2 ++ Design_Doc/Tech_Desc.md | 14 ++++++++------ deploy-rvs-prxy.sh | 32 ++++++++++++++++---------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Design_Doc/DevProc.md b/Design_Doc/DevProc.md index 8b940b7..4eee47b 100644 --- a/Design_Doc/DevProc.md +++ b/Design_Doc/DevProc.md @@ -1277,6 +1277,8 @@ ## make a generic rvs-prxy system +- In a case, i have two domains name, that means two .env-www-domain-com and .env-domain-com, their service are same to one container, say web-fe-1, i find it has one domain work, another does not. I see the reason as: it has two dynamic configuration files inside /etc/traefik/config/, say app-service-www.domain.com-web-fe-1.yml, and app-service-domain.com-web-fe-1.yml, inside them, the routers are same names, say web-fe-1-https and web-fe-1-http, the services name are same too, say web-fe-1-service. By observation, the names format of routers and services is container-name-https, container-name-http and container-name-service. So i aim to improve this name format rule, do not use container-name, it may share to diff. domains, so should use domain name inside the rule, eg. domain-name-https, domain-name-http, domain-name-service, etc. + - Currently .env-p2prly1-ivantito-com as: ``` DOMAIN_NAME="p2prly1.ivantito.com" diff --git a/Design_Doc/Tech_Desc.md b/Design_Doc/Tech_Desc.md index a80365d..f1e8a18 100644 --- a/Design_Doc/Tech_Desc.md +++ b/Design_Doc/Tech_Desc.md @@ -160,28 +160,30 @@ http: ```yaml http: routers: - -https: + -https: rule: 'Host(``)' - service: -service + service: -service tls: certResolver: letsencrypt entryPoints: - websecure - -http: + -http: rule: 'Host(``)' - service: -service + service: -service entryPoints: - web middlewares: - redirect-to-https services: - -service: + -service: loadBalancer: servers: - - url: 'http://:' + - url: 'http://:' passHostHeader: true ``` +Router, service, and middleware names use the domain (or domain-without-sub-path) as the prefix instead of the container name. This ensures unique resource names when multiple domains share the same backend container. The backend URL still references the container hostname for Docker networking. + **Entrypoints Configuration:** Default entrypoints (`web` on :80, `websecure` on :443) are defined in the docker-compose.yml command args. Additional entrypoints can be configured via the `EXTRA_ENTRYPOINTS` environment variable in `.env.rvs-prxy`: - Format: `name=:port/protocol,name2=:port` (comma-separated) diff --git a/deploy-rvs-prxy.sh b/deploy-rvs-prxy.sh index 8688308..1bf3ef2 100755 --- a/deploy-rvs-prxy.sh +++ b/deploy-rvs-prxy.sh @@ -1897,30 +1897,30 @@ configure_traefik_local() { cat > "$temp_config" << EOF http: routers: - ${LOCAL_SERVICE_NAME}-https: + ${domain_part}-https: rule: 'Host(\`${domain_part}\`) && PathPrefix(\`${path_part}\`)' - service: ${LOCAL_SERVICE_NAME}-service + service: ${domain_part}-service tls: certResolver: letsencrypt entryPoints: - websecure middlewares: - - ${LOCAL_SERVICE_NAME}-strip-prefix - ${LOCAL_SERVICE_NAME}-http: + - ${domain_part}-strip-prefix + ${domain_part}-http: rule: 'Host(\`${domain_part}\`) && PathPrefix(\`${path_part}\`)' - service: ${LOCAL_SERVICE_NAME}-service + service: ${domain_part}-service entryPoints: - web middlewares: - redirect-to-https - - ${LOCAL_SERVICE_NAME}-strip-prefix + - ${domain_part}-strip-prefix middlewares: - ${LOCAL_SERVICE_NAME}-strip-prefix: + ${domain_part}-strip-prefix: stripPrefix: prefixes: - ${path_part} services: - ${LOCAL_SERVICE_NAME}-service: + ${domain_part}-service: loadBalancer: servers: - url: 'http://${LOCAL_SERVICE_NAME}:${first_tcp_port}' @@ -1931,22 +1931,22 @@ EOF cat > "$temp_config" << EOF http: routers: - ${LOCAL_SERVICE_NAME}-https: + ${domain_part}-https: rule: 'Host(\`${DOMAIN_NAME}\`)' - service: ${LOCAL_SERVICE_NAME}-service + service: ${domain_part}-service tls: certResolver: letsencrypt entryPoints: - websecure - ${LOCAL_SERVICE_NAME}-http: + ${domain_part}-http: rule: 'Host(\`${DOMAIN_NAME}\`)' - service: ${LOCAL_SERVICE_NAME}-service + service: ${domain_part}-service entryPoints: - web middlewares: - redirect-to-https services: - ${LOCAL_SERVICE_NAME}-service: + ${domain_part}-service: loadBalancer: servers: - url: 'http://${LOCAL_SERVICE_NAME}:${first_tcp_port}' @@ -1994,12 +1994,12 @@ EOF udp: routers: - ${LOCAL_SERVICE_NAME}-${matching_ep}: + ${domain_part}-${matching_ep}: entryPoints: - ${matching_ep} - service: ${LOCAL_SERVICE_NAME}-udp + service: ${domain_part}-udp services: - ${LOCAL_SERVICE_NAME}-udp: + ${domain_part}-udp: loadBalancer: servers: - address: "${LOCAL_SERVICE_NAME}:${container_port}"