TIL Caddy is Awesome

I have been using the awesome Caddy web server (i find it easier than nginx) on a vps I use, as a person who manages to spin up a new subdomain/services every week/month. It's invaluable. Before using it, I didn't even know you could do that, you could have soo many domains use different server implementations and map them in a simple Caddyfile ! 


At the core, it's a web server (caddy/nginx, a robust, secure community developed) filtering/mapping individual requests to another web server. (What's crazy is my setup includes Caddy mapping to nginx due to "reasons"). But ya, it's fun and dead simple. 


The flow usually goes

1. I have a wacky idea

2. I code the server (easier due to "vibe-coding" nowadays), generally in Go (Python/NodeJS if my hands are tied)

2. I think about a subdomain and put a CNAME record in my DNS.

3. I put that new subdomain entry in Caddy mapped with the server port running locally on that VPS.


Caddy now takes care of both getting the SSL certs from Let's Encrypt and mapping requests to the subdomain.

It apparently does so via the "HOST" header in HTTP requests. See when caddy receives a request, there is no domain name, it has already been translated to the IP of the VPS, which is the same. So all those subdomains, domain mapping resolve into the same IPv4 address!


Here is my caddyfile

```

vps.osac.org.np {

        # Ai test infrastructure

        reverse_proxy localhost:8192

}

vps.osac.org.np:8181 {

        # Gpt manim root dir, used to serve generated gpt manim media and other static stuffs like worked solution etc

        root * /home/pykancha/dev/gpt-manim/latex2png

        file_server

}

notes.hemanta.dev {

        root * /home/pykancha/dev/http/notes

        file_server

}

til.hemanta.dev {

        root * /home/pykancha/dev/http/til

        file_server

}

til.hemanta.dev:7999 {

        handle_path /hman-212-til-server/* {

                reverse_proxy localhost:5999

        }

}

latexmcp.osac.org.np {

        reverse_proxy localhost:5443

}

vps.osac.org.np:8080 {

        reverse_proxy localhost:5293

}

vps.osac.org.np:8000 {

        reverse_proxy localhost:5000

}

vps.osac.org.np:8008 {

        reverse_proxy localhost:3008

}

vps.osac.org.np:8095 {

        reverse_proxy localhost:8090

```