Caddy, The kitchen sink of webservers

Reverse Proxy? CGI? Static Pages? Dynamic Pages? All can be done!

for the past few years (since 2017) i've been using Caddy for my static websites and as a proxy various other web services instead of nginx

Caddy v1

i started with what is now known as Caddy v1 with quite a basic caddyfile:

[domain expired] {
root /var/www/[domain name]
header / {
    Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
}
}

its really useful as it has auto SSL cert creation, no fumbling about with certbot, worked right out of the box and i instantly fell in love and started using it as a proxy server for various other things.

Caddy v2

It's now daemonized with caddy start, for foreground you can do caddy run
i have upgraded to Caddy v2 for all my sites in early 2022 as i was holding off upgrading but eventually caved in and learnt the new syntax, its almost plug and play for most cases though for some things I like to have auto https disabled (for older device compatibility) so i personally have this at the top of my caddyfile: (isn't the best way to do it, i'll eventually fix it)

{
        auto_https disable_redirects
}

but now some of my sites won't automatically redirect to https! here is a silly little workaround, adding another site block for port 80:

utsuho.rocks:80 {
        redir https://utsuho.rocks{uri}
}

Building, Plugins and Templates

writing plugins is entirely optional as there is a plethora of available plugins to install into your build, all entirely optional. if what you want isn't there writing your own middleware/plugins is ~relatively~ actually easy especially using xcaddy to build caddy, even with the prebuilt binaries you can still do some very cool things with templates including base64 encoding/decoding and dynamic middleware file directories.

UtsuhoBlogs Discord https://utsuho.rocks