From e13f7afcb832588a65bcce6da8b950075dad13db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20Micha=C5=82=20Ry=C5=9B?= <6430069+arrys@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:25:06 +0200 Subject: [PATCH] Fix traefik rule priority for media router (#4244) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add option to serve media files locally using nginx * Fix nginx media location and storage issue * Fix traefik django-media typo * Add certresolver property to web-media-router * Add trailing slash in nginx configuration to avoid path traversal exploits * Remove autoindexing from nginx configuration so nginx uses its default off setting * Use nginx to serve media files if cloud provider is None * Add back warning about lack of media files without Docker or Cloud providers * Update documentation * Fix typos and rephrase Co-authored-by: Arkadiusz Ryś * 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. * Add space to Traefik rule --------- Co-authored-by: Bruno Alla Co-authored-by: Bruno Alla --- .../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 ea57f4a5..85d9572b 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: