From 1900e90c2c50113216a18f2b87c8bb74ba38ffcc Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Sun, 25 Dec 2016 16:16:45 +0100 Subject: [PATCH] Integrated automatic locale redirect (#33) --- Dockerfile | 16 +++++++++------- docker/caddy.conf | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3e938a0..29df5ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,15 @@ FROM alpine:edge EXPOSE 80 RUN apk update && \ - apk add \ - caddy \ - mailcap && \ - rm -rf \ - /var/cache/apk/* + apk add wget mailcap ca-certificates && \ + rm -rf /var/cache/apk/* && \ + wget -O /tmp/caddy.tar.gz "https://caddyserver.com/download/build?os=linux&arch=amd64&features=locale%2Csearch" && \ + mkdir -p /tmp/caddy && \ + tar xvzf /tmp/caddy.tar.gz -C /tmp/caddy && \ + cp /tmp/caddy/caddy /usr/sbin/caddy && \ + rm -rf /tmp/caddy* -CMD ["/usr/sbin/caddy", "-conf", "/etc/caddy/caddy.conf"] +CMD ["/usr/sbin/caddy", "-conf", "/etc/caddy.conf"] -COPY docker/caddy.conf /etc/caddy/caddy.conf +COPY docker/caddy.conf /etc/caddy.conf COPY public /srv/www diff --git a/docker/caddy.conf b/docker/caddy.conf index 9d1d61a..d1b66ce 100644 --- a/docker/caddy.conf +++ b/docker/caddy.conf @@ -1,7 +1,39 @@ :80 { root /srv/www - errors { - 404 /404.html + locale en-US zh-CN zh-TW pt-BR nl-NL { + detect header } + + redir 301 { + if {path} match ^/$ + / /{>Detected-Locale}/ + } + + rewrite /en-US/ { + regexp (.*) + to /en-us/{1} + } + + rewrite /zh-CN/ { + regexp (.*) + to /zh-cn/{1} + } + + rewrite /zh-TW/ { + regexp (.*) + to /zh-tw/{1} + } + + rewrite /pt-BR/ { + regexp (.*) + to /pt-br/{1} + } + + rewrite /nl-NL/ { + regexp (.*) + to /nl-nl/{1} + } + + header / Vary "Accept-Language" }