This docker container listens on port 80 (default) and redirects all web traffic to the given target domain/URL.
- forked from MorbZ/docker-web-redirect
- Differences
- Add HTTP Redirect (drop URL Path)
- Code refactoring
- Differences
- GitHub Actions CI/CD Workflow (Publish to Docker Hub)
- (Required) The redirection type is set by the
REDIRECT_TYPEenvironment variable.- Available types
REWRITE: Performs URL RewriteREDIRECT: Performs HTTP Redirect
- Available types
- (Required) The target domain/URL is set by the
REDIRECT_TARGETenvironment variable.- Ex.
https://kftc.or.kr
- Ex.
- (Optional) The rewrite flag is set by the
REWRITE_FLAGenvironment variable. (Only used whenREDIRECT_TYPEisREWRITE.)- Available flags
permanent: Permanent rewrites. (Similar from HTTP 301 redirect)redirect: Temporary rewrites. (Similar from HTTP 302 redirect)
- Default flag is
redirect.
- Available flags
- (Optional) The redirection type is set by the
REDIRECT_CODEenvironment variable. (Only used whenREDIRECT_TYPEisREDIRECT.)- Available codes
301: Permanent redirects. Using GET method to redirected location.308: Permanent redirects. Using same method to redirected location. (Not supported by IE)303: Temporary redirects. Using GET method to redirected location.307: Temporary redirects. Using same method to redirected location. (Not supported by IE)302: Temporary redirects. Originally same as307, but most browsers do like303.
- Default code is
302.
- Available codes
# URL Rewrite
$ docker run --rm -d -e REDIRECT_TYPE=REWRITE REDIRECT_TARGET=https://kftc.or.kr -p 80:80 yoobato/docker-web-redirect
# HTTP Redirect
$ docker run --rm -d -e REDIRECT_TYPE=REDIRECT REDIRECT_TARGET=https://kftc.or.kr -p 80:80 yoobato/docker-web-redirectThis image can be combined with the nginxproxy/nginx-proxy.
A sample docker-compose file that redirects kftcold.net to kftcnew.net could look like this:
version: '3.8'
services:
redirect:
image: yoobato/docker-web-redirect
restart: always
environment:
- VIRTUAL_HOST=kftcold.net
- REDIRECT_TYPE=REDIRECT
- REDIRECT_TARGET=https://kftcnew.net
- REDIRECT_CODE=301Build multi-platform images (https://docs.docker.com/build/building/multi-platform/)
docker buildx build --platform linux/arm64,linux/amd64,linux/arm/v7 -t yoobato/docker-web-redirect:{version_tag} --push .