From 213f623b937326f6adfcb91187a526a733344a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20Ry=C5=9B?= Date: Sat, 1 Apr 2023 15:11:15 +0200 Subject: [PATCH] Change Traefik media router rule generation to force priority The web-secure-router could end up having priority over the web-media-router when the www subdomain was used. This fix adds the www subdomain to the web-media-router if it's also present in the web-secure-router rule. Traefik looks at the length of rules to determine priority when no explicit priority is set. The web-media-router needs to always have priority over the web-secure-router in order for the media files to be served. --- .../compose/production/traefik/traefik.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml b/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml index ea57f4a51..62cf0e391 100644 --- a/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml +++ b/{{cookiecutter.project_slug}}/compose/production/traefik/traefik.yml @@ -60,7 +60,11 @@ http: {%- if cookiecutter.cloud_provider == 'None' %} web-media-router: + {%- if cookiecutter.domain_name.count('.') == 1 %} + rule: "(Host(`{{ cookiecutter.domain_name }}`) || Host(`www.{{ cookiecutter.domain_name }}`))&& PathPrefix(`/media/`)" + {%- else %} rule: "Host(`{{ cookiecutter.domain_name }}`) && PathPrefix(`/media/`)" + {%- endif %} entryPoints: - web-secure middlewares: