Domain aliases based on env var #15

Closed
opened 2020-09-16 22:09:40 +00:00 by 3wordchant · 2 comments
Owner

E.g. if we set up an app on https://foo.swarm.autonomic.zone and then migrate it to https://foo.bar, it'd be nice to define the old URL as an alias so it redirects instead of 404ing.

I guess the question is how to turn a shell array or space-separated list into a Traefik routing rule?

This will also be useful for redirecting www subdomains, which we probably don't want to hard code into each stack.

E.g. if we set up an app on `https://foo.swarm.autonomic.zone` and then migrate it to `https://foo.bar`, it'd be nice to define the old URL as an alias so it redirects instead of 404ing. I guess the question is how to turn a shell array or space-separated list into a Traefik routing rule? This will also be useful for redirecting `www` subdomains, which we probably don't want to hard code into each stack.
3wordchant changed title from Method for easily adding domain aliases to Domain aliases based on env var 2020-09-17 21:57:21 +00:00
3wordchant added the
enhancement
label 2020-09-24 23:15:15 +00:00
Author
Owner
https://github.com/traefik/traefik/issues/572
Author
Owner

I've got what seems like a decent solution for this:

compose.yml:

- "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`${EXTRA_DOMAINS})"
- "traefik.http.routers.${STACK_NAME}.middlewares=${STACK_NAME}-redirect"
- "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLForceHost=true"
- "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLHost=${DOMAIN}"

.envrc:

# shellcheck disable=SC2016
export EXTRA_DOMAINS=', `additional.example.com`, `www.example.com`'

Syntax So Bad It Needs a shellcheck Exception™

I've got what seems like a decent solution for this: `compose.yml`: ``` - "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`${EXTRA_DOMAINS})" - "traefik.http.routers.${STACK_NAME}.middlewares=${STACK_NAME}-redirect" - "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLForceHost=true" - "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLHost=${DOMAIN}" ``` `.envrc`: ``` # shellcheck disable=SC2016 export EXTRA_DOMAINS=', `additional.example.com`, `www.example.com`' ``` Syntax So Bad It Needs a `shellcheck` Exception™
This repo is archived. You cannot comment on issues.
No description provided.