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™
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: coop-cloud/organising#15
No description provided.