Very simple Docker image, which redirects a request from www to non-www domain.
Note: the image should be able to handle any domain. "example.com" is used in this documentation as an example.
Contents:
- Usage
- How it works
- Why
- Requirements
- Contributing
- Testing locally
- Release process
- For Shipmight users
- License
docker run --rm -p 8080:80 ghcr.io/shipmight/nginx-www-redirect
See GitHub packages for available tags.
Any request with the header Host
header beginning with www.
returns a 301 redirect to the non-www domain.
When the Host
header does not begin with www.
, a 404
response is returned.
If you need to redirect visitors from a www-domain to the non-www equivalent, and have an architecture where deploying a new container which accepts traffic from www-domains is easy, you can use this image to achieve the redirect.
This image is proven to run fine with as low as 128MB of memory (probably way less) and some CPU cycles.
The image size is ~24MB. It is based on nginx-alpine.
Build the image:
docker build -t nginx-www-redirect:dev .
Start it:
docker run --rm -p 8080:80 nginx-www-redirect:dev
Make a request and observe returned headers:
$ curl -v -H 'Host: www.example.com' http://127.0.0.1:8080
< HTTP/1.1 301 Moved Permanently
< Location: http://example.com/
...
For automation purposes there's a script bash test.sh
, which is used in the CI.
Push a new tag to trigger the release-workflow which builds and pushes new image to ghcr.
git pull
git tag v1.0.0
git push origin v1.0.0
Note: domain redirects (including www to non-www) will be an out-of-the-box feature in Shipmight. In the meantime, you can use this image.
Released under the Apache 2 license. See LICENSE.