Back to articles
Security & Anti-DDoS

Optimizing Caddy Server: Solution for Handling Over 20,000 Customer Domains with On-Demand TLS

Guide to optimizing Caddy Server for processing over 20,000 customer domains with On-Demand TLS, ensuring high performance, security, and scalability on DDoS-protected VPS.

DPTCloud Engineering4 min read
Optimizing Caddy Server: Solution for Handling Over 20,000 Customer Domains with On-Demand TLS

Optimizing Caddy Server for Over 20,000 Customer Domains

Processing tens of thousands of domains on a single web server demands an efficient solution in terms of performance, security, and scalability. Caddy Server, with its On-Demand TLS feature that automatically issues Let's Encrypt certificates, is an ideal choice for DDoS-protected VPS environments. This guide explores how to optimize Caddy Server to efficiently and securely handle over 20,000 customer domains.

On-Demand TLS: Automating Certificate Issuance

On-Demand TLS in Caddy Server enables automatic issuance of TLS certificates only when a domain is accessed, rather than pre-issuing for all domains. This reduces resource overhead and improves system performance.

To enable On-Demand TLS, configure your Caddyfile as follows:

{\n    on_demand_tls\n}\n\nexample.com {\n    root * /var/www/example\n    file_server\n}\n

Note: Caddy will automatically issue and renew Let's Encrypt certificates when needed upon domain access.

Performance Optimization and System Load Reduction

To handle 20,000 domains effectively, optimize Caddy Server to reduce CPU, RAM, and I/O usage. Consider these optimization steps:

  • Domain Grouping: Group domains by geographical region or service type to minimize simultaneous certificate issuance.
  • Rate Limiting: Apply rate limiting to prevent excessive access from a single IP.
  • Load Balancing: Use a load balancer to distribute traffic across multiple Caddy servers.
  • Content Caching: Enable content caching via plugins such as cache or reverse_proxy to reduce server load.

Running Caddy Server on DDoS-Protected VPS

To ensure stability and security, deploy Caddy Server on DDoS-protected VPS services at DPTCloud. Features like Anycast L3/L4/L7 and 99.98% SLA protect the system from DDoS attacks and ensure high uptime.

Refer to the basic VPS DDoS protection guide at Basic VPS DDoS Protection with Fail2Ban, Cloudflare, and iptables.

Configuration Validation and Verification

After configuration, verify that all domains are working correctly:

  1. Run Caddy configuration validation:
  2. caddy validate
  3. Restart the Caddy service:
  4. sudo systemctl restart caddy
  5. Access a domain to test TLS issuance:
  6. curl -I https://example.com

Troubleshooting and Maintenance

Common issues when managing many domains include:

  • Certificate Issuance Failure: Check Caddy logs using journalctl -u caddy -f to identify errors.
  • Performance Degradation: Monitor system resources with htop or top and adjust configuration accordingly.
  • Unreachable Domains: Verify DNS settings and firewall rules to ensure correct domain access.

For maintenance, set up automatic certificate renewal with:

caddy reload --config /etc/caddy/Caddyfile

References

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478