Custom Domain Setup
Connect your own domain to Firebase Hosting for a professional web presence with automatic SSL certificates and global CDN distribution.
Quick Setup Overview
Timeline:
- Verification: 5-30 minutes
- DNS propagation: 0-48 hours
- SSL certificate: 0-24 hours after DNS
Step-by-Step Guide
Step 1: Add Custom Domain
- Go to Firebase Console
- Select your project → Hosting
- Click Add custom domain
- Enter your domain (e.g.,
example.com
)
Step 2: Verify Domain Ownership
Firebase provides a TXT record for verification:
Type: TXT
Host: @ (or your domain)
Value: firebase=YOUR_VERIFICATION_CODE
TTL: 3600 (or default)
Verification Methods:
- TXT record (recommended) - Doesn't affect site
- Upload HTML file - Alternative method
- Existing Google verification - If previously verified
Step 3: Configure DNS Records
After verification, add these records:
For apex domain (example.com):
Type: A
Host: @
Value: 151.101.1.195
TTL: 3600
Type: A
Host: @
Value: 151.101.65.195
TTL: 3600
Type: AAAA (IPv6)
Host: @
Value: 2a00:1450:4010:c08::65
TTL: 3600
For subdomain (www.example.com):
Type: CNAME
Host: www
Value: YOUR-PROJECT.web.app
TTL: 3600
Domain Configuration Patterns
Pattern 1: Apex + WWW Redirect
Most common setup - example.com
redirects to www.example.com
:
{
"hosting": {
"redirects": [{
"source": "https://example.com/**",
"destination": "https://www.example.com/:splat",
"type": 301
}]
}
}
Pattern 2: WWW to Apex Redirect
Prefer non-www - www.example.com
redirects to example.com
:
{
"hosting": {
"redirects": [{
"source": "https://www.example.com/**",
"destination": "https://example.com/:splat",
"type": 301
}]
}
}
Pattern 3: Multiple Domains
Point multiple domains to same site:
- Add each domain in Firebase Console
- Configure DNS for each
- Set up redirects to primary domain:
{
"hosting": {
"redirects": [
{
"regex": "^https://example\\.(net|org)/(.*)$",
"destination": "https://example.com/:2",
"type": 301
}
]
}
}
SSL Certificate Management
Automatic SSL Provisioning
Firebase automatically:
- Generates SSL certificates via Let's Encrypt
- Renews certificates before expiration
- Supports wildcard certificates for subdomains
- Provides A+ SSL rating
SSL Provisioning Timeline
Troubleshooting SSL Issues
Issue | Cause | Solution |
---|---|---|
SSL pending > 24h | DNS not propagated | Check DNS with dig command |
Certificate error | Old DNS cache | Clear browser cache, wait |
Mixed content warnings | HTTP resources | Update all resources to HTTPS |
SSL not renewing | DNS changed | Reverify domain |
Advanced DNS Configurations
Using Cloudflare
If using Cloudflare DNS:
- Set SSL/TLS to "Full" (not Flexible)
- Disable proxy (orange cloud) initially
- Add records as shown above
- Wait for SSL provisioning
- Enable proxy after SSL is active (optional)
DNS Provider-Specific Guides
GoDaddy:
1. DNS Management → Add → A Record
2. Host: @, Points to: Firebase IPs
3. Save changes
Namecheap:
1. Advanced DNS → Add New Record
2. Type: A Record, Host: @
3. Value: Firebase IPs
Google Domains:
1. DNS → Custom records
2. Add A records with Firebase IPs
3. Add AAAA records for IPv6
Subdomain Strategies
Subdomain Setup
Different subdomains for different purposes:
# Main site
example.com → Marketing site
# Application
app.example.com → Web application
# API
api.example.com → Cloud Functions/Run
# Documentation
docs.example.com → Documentation site
# Staging
staging.example.com → Test environment
Wildcard Subdomains
For dynamic subdomains (e.g., user.example.com):
- Not directly supported by Firebase Hosting
- Use Cloud Run with custom domain mapping
- Or implement routing logic in Cloud Functions
Domain Migration
Moving from Another Host
-
Reduce TTL - 24 hours before migration
Old TTL: 86400 → New TTL: 300
-
Set up Firebase - Complete verification
-
Update DNS - Point to Firebase
-
Monitor traffic - Check analytics
-
Increase TTL - After successful migration
TTL: 300 → TTL: 3600
Zero-Downtime Migration
Email Configuration
Important: Email Hosting
Firebase Hosting does NOT provide email services. When moving domains:
- Keep existing MX records
- Only update A/AAAA records
- Don't delete email-related records
Example DNS with email:
# Website (Firebase)
A @ 151.101.1.195
AAAA @ 2a00:1450:4010:c08::65
# Email (Keep existing)
MX @ 10 mail.example.com
TXT @ "v=spf1 include:..."
Monitoring Domain Health
DNS Verification Tools
# Check A records
dig example.com A
# Check AAAA records
dig example.com AAAA
# Check all records
dig example.com ANY
# Check from specific nameserver
dig @8.8.8.8 example.com
# Online tools
# - whatsmydns.net
# - dnschecker.org
# - mxtoolbox.com
SSL Certificate Check
# Check certificate details
openssl s_client -connect example.com:443 -servername example.com
# Check expiration
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates
Troubleshooting Guide
Domain Not Working
Check verification status:
- Firebase Console → Hosting → View domains
- Look for ⚠️ warning icons
- Re-verify if needed
Verify DNS propagation:
# Should return Firebase IPs
nslookup example.com
dig example.com
Common DNS issues:
- Cached old records → Wait or flush DNS
- Wrong record type → Use A for apex, CNAME for subdomain
- Proxy enabled → Disable Cloudflare proxy initially
"Website Not Secure" Error
Causes:
- SSL still provisioning (wait up to 24h)
- DNS not fully propagated
- Mixed content (HTTP resources)
- Browser cache (try incognito)
Solutions:
// Force HTTPS redirect
if (location.protocol !== 'https:') {
location.replace('https:' + window.location.href.substring(window.location.protocol.length));
}
Redirect Loops
Common cause: Conflicting redirects
{
"hosting": {
"redirects": [
{
"source": "/",
"destination": "https://www.example.com/",
"type": 301
}
],
"headers": [{
"source": "**",
"headers": [{
"key": "Strict-Transport-Security",
"value": "max-age=63072000; includeSubDomains; preload"
}]
}]
}
}
Best Practices
1. Domain Setup Checklist
- Reduce TTL before migration
- Verify domain ownership
- Add all required DNS records
- Test with Firebase URL first
- Monitor SSL provisioning
- Set up redirects (www/non-www)
- Update sitemap.xml
- Submit to Search Console
2. Security Headers
{
"headers": [{
"source": "**",
"headers": [
{
"key": "Strict-Transport-Security",
"value": "max-age=31536000; includeSubDomains; preload"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
}
]
}]
}
3. SEO Considerations
- Use 301 redirects for permanent moves
- Update canonical URLs
- Maintain URL structure if possible
- Update internal links
- Monitor search rankings
Advanced Configurations
Internationalization Domains
# Country-specific domains
example.com → International (English)
example.de → Germany
example.fr → France
example.co.uk → United Kingdom
Configure with i18n:
{
"hosting": {
"i18n": {
"root": "/localized-content"
}
}
}
Domain Aliases
For multiple domains pointing to same content:
- Add all domains in Firebase Console
- Choose primary domain
- Redirect others to primary
- Update canonical tags
Cost Considerations
What's Free
- ✅ SSL certificates
- ✅ Unlimited custom domains
- ✅ Automatic renewals
- ✅ Global CDN distribution
Potential Costs
- Domain registration (external)
- Premium DNS services (optional)
- Bandwidth usage (standard Firebase pricing)
Next Steps
- Set up Multi-Sites for complex projects
- Configure Security headers
- Implement Monitoring for your domains
- Optimize Performance with proper caching
Pro Tip: Always verify DNS changes from multiple locations using online tools. DNS propagation can vary by region, and checking from different locations ensures global availability! 🌍