A 4.2MB Domain Redirect Service
Got a bunch of idle domains and want a redirect service, but Caddy’s config makes your head hurt? This 4.2MB Go service might be exactly what you need.
domain-redirect is a lightweight service built specifically for domain redirection. It turns complex config into just a few environment variables. Simple and flexible, and suitable for production use.
Project: https://github.com/nexmoe/domain-redirect
Three‑Minute Quick Start
The easiest way is Docker:
docker run -d \
-p 8080:8080 \
-e DOMAIN_MAPPING_1=example.com->https://target1.com,https://target2.com \
nexmoe/domain-redirect
This command starts a redirect service that round‑robins requests for example.com to two targets.
PORT: listening port (default 8080)PRESERVE_PATH: keep original path (default false). If “true”, redirects keep request pathINCLUDE_REFERRAL: include referrer domain info (default false). If “true”, adds arefparamENABLE_TIMESTAMP: add timestamp param (default false). If “true”, adds_tto prevent caching
For more complex configs, use docker-compose.yml:
version: '3'
services:
domain-redirect:
image: nexmoe/domain-redirect
ports:
- "8080:8080"
environment:
- DOMAIN_MAPPING_1=blog.example.com->https://blog.target.com
- DOMAIN_MAPPING_2=shop.example.com->https://shop1.com,https://shop2.com
- PRESERVE_PATH=true
- INCLUDE_REFERRAL=true
restart: unless-stopped
Now all domains redirect per rules. Paths are preserved and referrer info is added to the URL for analytics.
Full Config Reference
Domain Mapping
Each mapping rule uses DOMAIN_MAPPING_*:
DOMAIN_MAPPING_<ANY_NAME>=<domain>-><target1>,<target2>,...
Example:
DOMAIN_MAPPING_1=example.com->https://target1.com,https://target2.com
DOMAIN_MAPPING_BLOG=blog.example.com->https://myblog.com
DOMAIN_MAPPING_SHOP=shop.example.com->https://shop1.com,https://shop2.com,https://shop3.com
Example
Assume:
DOMAIN_MAPPING_1=example.com->https://target1.com,https://target2.com
PRESERVE_PATH=true
INCLUDE_REFERRAL=true
ENABLE_TIMESTAMP=true
Requesting http://example.com/api/users might redirect to:
https://target1.com/api/users?ref=example.com&_t=1672531200
Lightweight by Design
The image is only 4.2MB and uses 1.277MB memory. This reduces costs and makes scaling easy.
Traditional servers like Nginx/Apache are tens of MBs — overkill for redirects. domain-redirect is written in Go: small binaries, low runtime overhead.
More importantly, it uses environment variables for config. Compared with config files, env vars are better for containerized deployments:
- Orchestrators (e.g., Kubernetes) support env vars natively
- Config changes don’t require rebuilding images, just restart
- Secrets can be managed safely
Referral Tracking & Analytics
When INCLUDE_REFERRAL is enabled, redirected URLs automatically include a ref parameter with the source domain.
This solves a key pain point: tracking traffic sources. The HTTP Referer header is often stripped or modified by browsers, while URL parameters are more reliable.
Combined with analytics tools like Google Analytics, you can measure which domains drive traffic and evaluate their value — especially useful if you own many domains.
KISS (Keep It Simple, Stupid)
domain-redirect is not trying to be a full reverse proxy. It focuses on redirection only.
Go is a thoughtful choice. It’s compiled, so deployments are consistent, and you don’t worry about runtime versions. Go’s concurrency model is ideal for handling large numbers of redirects.
Round‑robin state is stored in memory and resets on restart. This sacrifices persistence but keeps architecture simple — a reasonable trade‑off for redirects.