Tech AI Insights

Caddy vs Nginx : A Complete Comparison of Web Servers

Caddy vs Nginx

  • Caddy is the newer web server on the block, and it’s built to be simple, automatic, What Are Caddy and Nginx?nd secure out of the box. It’s most famous for automatic HTTPS with built-in Let’s Encrypt support.
  • Nginx (pronounced “engine-x”) is a veteran web server. It’s been around for a long time and is known for being fast, stable, and highly configurable. It’s often used as a reverse proxy, load balancer, or static file server.

When Should You Use Caddy?

Go with Caddy if:

  • Automatic HTTPS and SSL by default—no setup, no renewal, no pain..
  • You’re new to web servers and want to get started quickly.
  • You’re hosting a simple site, static files, or a few services.
  • You want a config that’s clean and human-readable.

Example Caddyfile (it’s this easy):

Set up the Virtual host

  1. Create a new site directory under /var/www/html.Let’s name it techai:
    sudo mkdir /var/www/html/techai
    
  2. Add a temporary index.html file (print something)to test if the virtual host is working:

    ⚠️ Once you’ve verified everything is working, you can safely delete this file and either:

    • Clone your Git project, or
    • Start a fresh project in the techai folder.
  3. Optional(if you facing permission issue): Set the proper permissions for the techai directory (for development only):
    sudo chmod -R 777 /var/www/html/techai
    

    🔒 Note: 777 gives full read/write/execute access to all users, which is insecure for production. Use it only for quick testing or local development.

  4. Open Caddyfile:
sudo nano /etc/caddy/Caddyfile
  1. Add this code to the file
tech-ai.codewebs.in {
    root * /var/www/html/techai/public
    php_fastcgi unix//run/php/php7.2-fpm.sock
    file_server
    encode gzip
    log {
        output file /var/log/caddy/access.log
    }
}

Useful commands

sudo systemctl stop caddy      # Stop Caddy
sudo systemctl start caddy      # Start Caddy
sudo systemctl restart caddy    # Restart Caddy
sudo systemctl reload caddy     # Reload configuration without downtime (hot reload)
sudo systemctl status caddy

When Should You Use Nginx?

Choose Nginx if:

  • Manual SSL setup required—generate certs, configure paths, and handle renewals yourself.
  • You need tight control and advanced features.
  • You’re working on a complex deployment or high-traffic site.
  • You’re part of a team that already uses Nginx.
  • You need custom modules or integration with older tools.

Example Nginx config (more complex):

Set up the Virtual host

If you’re setting this up from scratch, just follow steps 1 to 3 mentioned above to configure your project with Caddy.

  1. Now go to below path:
cd /etc/nginx/sites-available
  1. Make a new file with your domain name. nano techai Add the below code to the file:
server {
    listen 80;
    server_name tech-ai.co;
    root /var/www/html/techai/public;
    index index.html index.htm index.php;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \\.php$ {
        proxy_read_timeout 300;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
    location ~ /\\.ht {
        deny all;
    }
}

User commands

sudo systemctl stop nginx   # Stop Nginx
sudo systemctl start nginx   # Start Nginx
sudo systemctl restart nginx   # Restart Nginx
sudo systemctl reload nginx   # Reload Nginx
sudo systemctl status nginx    

Bottom Line: Which One Should You Use?

  • Use Caddy if you value simplicity, speed, and automation. It’s perfect for most personal projects, small apps, or modern devs who want fewer headaches.
  • Use Nginx if you need more control, are working on legacy systems, or require enterprise-level tweaking.

TL;DR:

🟢 Caddy = Easy, smart, secure by default.

🟠 Nginx = Powerful, flexible, but more complex.

For more insightful tutorials, visit our Tech Blogs and explore the latest in Laravel, AI, and Vue.js development!

Scroll to Top