Multi-Domain Web Hosting on a Single IP Address
System DesignModel answerLast updated
Design a solution to serve three independent websites with separate domain names from one server with a single public IP address.
You're tasked with deploying websites for three independent small businesses—a café, a flower shop, and a bookstore—on a single Linux server that has only one public IPv4 address. Each business needs its own domain name (for example: cafe.com, flowers.com, books.com).
Design an architecture that enables all three websites to coexist on this shared infrastructure.
Your solution should address:
- DNS configuration — How do you point multiple domain names to one IP?
- Request routing — How does the server determine which site a visitor wants when HTTP/HTTPS requests arrive?
- Certificate handling — How do you secure each site with HTTPS?
- Operations and security — What isolation, monitoring, and deployment practices would you implement?
Explain the technical mechanisms that make this possible and discuss practical trade-offs.
Hints
Hint 1
Think about what information browsers send that identifies which domain they're trying to reach
Hint 2
TLS handshakes happen before HTTP headers can be read—how does the server pick the right certificate?
Hint 3
Consider how to prevent one site's issues from affecting the others
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer: Multi-Domain Hosting Architecture
This problem tests understanding of fundamental web infrastructure: how browsers identify which site they want, how servers route traffic accordingly, and how to operate multi-tenant systems safely.
Core Insight
The key realization is that a single IP address can serve unlimited hostnames. The client explicitly tells the server which site it's requesting through two mechanisms:
- The HTTP
Hostheader for plaintext traffic - The SNI (Server Name Indication) extension for encrypted connections
These mechanisms enable name-based virtual hosting.
1. DNS Layer
Each business registers their domain independently. In each domain's DNS zone, create A records pointing to the shared server IP:
cafe.com. A 198.51.100.50
www.cafe.com. CNAME cafe.com.
flowers.com. A 198.51.100.50
www.flowers.com. CNAME flowers.com.
books.com. A 198.51.100.50
www.books.com. CNAME books.com.
Key points:
- DNS performs only name-to-address translation. It doesn't carry information about which site the user wants—that comes later.
- Multiple domains can resolve to the same IP without conflict.
- Use A records for apex domains; CNAME works for subdomains like
www. - Set reasonable TTL values (5–60 minutes) to balance caching with migration flexibility.
- If the server has IPv6, add AAAA records as well.
2. HTTP Request Routing
Deploy a single reverse proxy (Nginx, Apache, Caddy, or Traefik) listening on ports 80 and 443. Configure it with virtual hosts for each domain.
For HTTP: The proxy inspects the Host header in every request:
GET /menu HTTP/1.1
Host: cafe.com
It matches this against configured server blocks and routes to the appropriate backend.
For HTTPS: The challenge is that TLS encryption starts before HTTP headers are visible. The solution is Server Name Indication (SNI)—an extension where the browser includes the target hostname in the plaintext TLS ClientHello. The proxy:
- Reads the SNI hostname from the ClientHello
- Selects the matching certificate
- Completes the TLS handshake
- Decrypts and routes the HTTP request
All modern browsers support SNI (since IE 7 on Vista, circa 2006).
Nginx configuration example:
# Redirect all HTTP to HTTPS
server {
listen 80;
server_name cafe.com www.cafe.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name cafe.com www.cafe.com;
ssl_certificate /etc/ssl/certs/cafe.com.crt;
ssl_certificate_key /etc/ssl/private/cafe.com.key;
root /var/www/cafe;
access_log /var/log/nginx/cafe.access.log;
error_log /var/log/nginx/cafe.error.log;
}
server {
listen 443 ssl http2;
server_name flowers.com www.flowers.com;
ssl_certificate /etc/ssl/certs/flowers.com.crt;
ssl_certificate_key /etc/ssl/private/flowers.com.key;
# Proxy to application server
location / {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
# Reject requests to unknown domains
server {
listen 443 ssl default_server;
ssl_reject_handshake on;
return 444;
}
The default server is critical—without it, requests to unknown hostnames or raw IP addresses would leak one tenant's content to arbitrary visitors.
3. TLS Certificate Management
Use Let's Encrypt with an ACME client (certbot or Caddy's built-in automation):
certbot certonly --webroot -w /var/www/acme \
-d cafe.com -d www.cafe.com
certbot certonly --webroot -w /var/www/acme \
-d flowers.com -d www.flowers.com
Certificate strategy: Obtain separate certificates for each business rather than one multi-domain certificate. Reasons:
- Privacy: Multi-domain certificates expose all customer domains to anyone inspecting the certificate
- Independence: One domain's DNS issues won't block renewal for others
- Lifecycle: Onboarding/offboarding customers doesn't require reissuing everyone's certificate
Operational requirements:
- Certificates expire after 90 days; automate renewal with a cron job or systemd timer
- Reload the proxy gracefully after renewal (
nginx -s reload) - Monitor certificate expiry dates and alert at 14 days remaining
- Protect private keys with strict permissions (root-owned, mode 0600)
Security hardening:
- Enforce TLS 1.2+ with strong cipher suites
- Enable HSTS headers once HTTPS is stable
- Redirect all HTTP traffic to HTTPS
- Consider OCSP stapling for faster handshakes
4. Operations and Security
Tenant isolation (critical for multi-tenancy):
- Run each site under a separate Unix user with distinct document roots (
/srv/cafe,/srv/flowers,/srv/books) - Set restrictive permissions (0750) so one site's compromise can't read another's files
- Use separate database users with minimal privileges
- Better yet: run each site in its own container with:
- CPU/memory limits to prevent resource exhaustion
- Network isolation (only the proxy is exposed publicly)
- Read-only filesystems where feasible
Firewall and attack surface:
- Allow only ports 22 (SSH), 80, and 443 through the firewall
- Backend services listen on localhost or Unix sockets only
- Harden SSH: key-only authentication, no root login, fail2ban for brute-force protection
- Implement per-host rate limiting to mitigate bots and scrapers
Logging and observability:
- Maintain separate access and error logs per domain so each business's traffic is isolated for analysis
- Rotate logs regularly with logrotate
- Set up uptime monitoring per domain (not just per IP)
- Monitor certificate expiry dates
- Track resource usage per tenant to detect anomalies
Deployment practices:
- Validate configuration changes (
nginx -t) before applying - Use graceful reloads to avoid connection drops
- Deploy atomically (symlink swaps or container replacements)
- Manage configurations as code (Ansible, Terraform) for reproducibility
- A configuration error in one site must never bring down the entire server
Common mistakes to avoid:
- Forgetting the default server block, which leaks content to unknown hostnames
- Using one multi-domain certificate, which creates operational coupling
- Not monitoring certificate expiry, leading to silent outages
- Inadequate isolation between tenants, allowing cross-contamination
- Testing only HTTP and discovering SNI issues in production
Scalability note: This single-server approach is appropriate for low-traffic sites. For higher loads, you'd move to a load balancer distributing across multiple backend servers, but the DNS, SNI, and routing principles remain identical.
Summary
The solution leverages DNS for name resolution, SNI for HTTPS routing, and a reverse proxy for request multiplexing. Success requires understanding the HTTP Host header, TLS handshake mechanics, and multi-tenant isolation principles. The architecture trades infrastructure cost for operational complexity—managing multiple tenants on shared hardware demands careful attention to security boundaries, monitoring, and configuration management.