Docs / Web Servers / Setting Up Caddy Web Server with Automatic HTTPS

Setting Up Caddy Web Server with Automatic HTTPS

By Admin · Feb 21, 2026 · Updated Apr 23, 2026 · 4 views · 2 min read

Setting Up Caddy Web Server with Automatic HTTPS is a common requirement for VPS administrators. This guide provides practical instructions that you can follow on Ubuntu 22.04/24.04 or Debian 12, though most steps apply to other distributions as well.

Prerequisites

  • A web server installed (Nginx or Apache)
  • A VPS running Ubuntu 22.04 or later (2GB+ RAM recommended)
  • SSL certificate or Certbot for Let's Encrypt
  • Basic familiarity with the Linux command line

Server Installation

When scaling this setup, consider vertical scaling (adding more RAM/CPU) first, as it's simpler to implement. Horizontal scaling adds complexity but may be necessary for high-traffic applications.


# /etc/nginx/sites-available/caddy.conf
server {
    listen 80;
    server_name example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Note that file paths may vary depending on your Linux distribution. The examples here are for Debian/Ubuntu; adjust paths accordingly for RHEL/CentOS-based systems.

Virtual Host Configuration

Performance benchmarks show that properly tuned caddy can handle significantly more concurrent connections than the default configuration. The key improvements come from adjusting worker processes and connection pooling.


# Test and reload Nginx configuration
sudo nginx -t
sudo systemctl reload nginx

# Check access and error logs
sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log

The configuration above sets the recommended values for a VPS with 2-4GB of RAM. Adjust the memory-related settings proportionally if your server has different specifications.

Important Notes

Security should be a primary consideration when configuring caddy. Always use strong passwords, keep software updated, and restrict network access to only the necessary ports and IP addresses.

Conclusion

This guide covered the essential steps for working with caddy on a VPS environment. For more advanced configurations, refer to the official documentation. Don't hesitate to reach out to our support team if you need help with your specific setup.

Was this article helpful?