Overview
Dubly supports hosting short links on multiple custom domains. Each link is associated with a specific domain, allowing you to organize links by brand, campaign, or purpose.How Multi-Domain Works
Dubly validates every link creation and update against a configured allowlist of domains. This prevents unauthorized domains from being used in your installation.Domain Validation
Domain checking is case-insensitive and uses exact matching as defined in internal/config/config.go:66:Domain validation happens on every link creation and update. If a domain is not in the allowlist, the API will return a 400 Bad Request error.
Configuration Methods
Environment Variable
Domains are configured via theDUBLY_DOMAINS environment variable as a comma-separated list:
DUBLY_DOMAINS is a required environment variable. Dubly will not start without at least one domain configured.Using the add-domain.sh Script
For production installations using the install script, Dubly includes a helper script to add domains without manual editing:- Validates the domain format (must contain at least one dot, no spaces)
- Checks for duplicates in the existing domain list
- Updates the .env file by appending the domain to
DUBLY_DOMAINS - Updates the Caddyfile to serve the new domain
- Restarts services (dubly and caddy systemd units)
Script Implementation
The domain validation logic from scripts/add-domain.sh:46:DNS Configuration
For each domain you add, you must configure DNS to point to your Dubly server:-
Create an A record pointing to your server’s IP address:
-
If using IPv6, also create an AAAA record:
- Wait for DNS propagation (usually 5-60 minutes)
-
Verify DNS resolution:
The add-domain.sh script reminds you to configure DNS after adding a domain. The admin panel includes DNS verification on the Domains page.
Web Server Configuration
Caddy (Recommended)
If you used the official install script, your Caddyfile will automatically be updated by add-domain.sh. The Caddyfile format is:Manual Configuration
If you’re not using the install script, manually add each domain to your reverse proxy configuration. Nginx:Ensure you set the Host header correctly when proxying. Dubly uses the Host header to determine which domain a request is for.
Domain Routing
When a request arrives, Dubly extracts the domain from the Host header and normalizes it in internal/handlers/redirect.go:24:Slug Uniqueness
Slugs are unique per-domain, enforced by a database constraint on(slug, domain). This means:
short.example.com/productandgo.myapp.com/productcan coexist as different links- You cannot create two links with the same slug on the same domain
- Slug collision detection in internal/models/link.go:121 checks both slug and domain:
This check includes soft-deleted links to prevent UNIQUE constraint violations during slug auto-generation.
Removing Domains
To remove a domain from your installation:- Edit
/opt/dubly/.env(or your .env file location) - Remove the domain from the
DUBLY_DOMAINScomma-separated list - Update your Caddyfile or reverse proxy configuration
- Restart services:
Best Practices
Use Descriptive Domains
Choose domain names that reflect their purpose:go.company.comfor internal employee linkspromo.brand.comfor marketing campaignsevent.conference.comfor event-specific links
SSL/TLS Certificates
Caddy automatically provisions Let’s Encrypt certificates for all configured domains. For manual setups:- Use a wildcard certificate if you have many subdomains
- Ensure your web server is configured for HTTPS on all domains
- Dubly itself doesn’t handle TLS; your reverse proxy should
Domain Verification
Before creating links on a new domain, verify:- DNS resolves correctly:
dig +short your-domain.com - Web server routes to Dubly:
curl -I http://your-domain.com - Domain is in allowlist: Check the Domains page in admin panel
Troubleshooting
”domain not allowed” Error
Cause: The domain is not inDUBLY_DOMAINS
Solution: Add the domain using add-domain.sh or by editing .env directly and restarting
Links Don’t Redirect
Cause: DNS not pointing to server, or web server not configured Solution: Verify DNS withdig, check web server logs, ensure reverse proxy forwards to Dubly