I used almost all major web server out there in the past, IIS, Apache, Nginx, Lighttpd, Monkey. They are all powerful solutions. But Caddy v2 really bring the ease of configuration into next level. Multi-site config is so clean, tidy with Caddyfile + snippets. I am having so much fun and satisfaction with Caddy.
Take my theme demo site SK1, SK2 and SK3 as example. They use almost identical settings. With Caddy, I can do the following:
(site_options) {
encode gzip
file_server
handle_errors {
rewrite * /{http.error.status_code}.html
file_server
}
header /css/* Cache-Control max-age=3600
header /favicon.ico Cache-Control max-age=3600
header /img/* Cache-Control max-age=3600
header /js/* Cache-Control max-age=3600
import cors
root * /www/site/{host}
}
sk1.jsiu.dev sk2.jsiu.dev sk3.jsiu.dev {
import site_options
}
I don’t need to repeat them in 3 blocks, nor 3 separate files. Clean, tidy, simple and beautiful.
Or for my main site johnsiu.com, I need so many redirect as I switched blogging platform multiple times:
(_redir) {
@{args.0} {
not file /{path} /{path}/ /{path}index.html /{path}/index.html
not path_regexp r {args.1}/.*
path_regexp r ^{args.0}/?(?P<goto>.*)$
}
redir @{args.0} {args.1}/{re.r.goto}
}
(_tryfile) {
@{args.0} {
file {args.0}/{path}index.html {args.0}/{path}/index.html
not file {path}index.html {path}/index.html
not path /myip /myip/
path_regexp try ^/(?P<file>[^/]+)/?$
}
redir @{args.0} {args.0}/{re.try.file}
}
johnsiu.com {
import _myip /myip
import _myip /myip/
import _redir /\d{4}/\d{2}(/\d{2})? /blog
import _redir /category /tags
import _redir /cheatsheet /blog
import _redir /index.php
import _redir /tag /tags
import _redir /wp-login.php
#import _redir / /blog
import _tryfile /blog
import site_options
templates /home/myip/
}
Logic can be deployed and re-used. The intention of each line become so clear. (Thank @francislavoie for helping to make _redir
work!! )
I put all snippets I come up with and using so far in a blog:
Let me know what you think. Or more crazy ideas on snippets.