最近把用了十几年的反向代理Nginx替换为了caddy.
首先我的这个需求可能不适合你,毕竟替换的学习成本比较高.
但是caddy的灵活性更适合我,nginx的灵活性和重新编译都太麻烦了。
本站使用的caddyfile的几个example可以快速入门caddy:
root@VM-zlNr9iaPx8gT:~# cat /etc/caddy/Caddyfile
````file
{ # for metrics
servers {
metrics
}
}
forum.magentochina.org:443 { # reverse proxy for discourse
reverse_proxy {
to 127.0.0.1:8080
transport http {
keepalive 30m
}
}
encode zstd gzip
tls shuai.zend@qq.com
log {
output file /var/log/forum.access.log {
roll_size 1gb
roll_keep 5
roll_keep_for 720h
}
format json
level DEBUG
}
}
doc.magentochina.org:443 {
root * /var/www/doc.magentochina.org/_site
file_server
encode gzip zstd
tls shuai.zend@qq.com
}
www.magentochina.org:443, magentochina.org:443 { # for wordpress
root * /var/www/magentochina.org
encode gzip zstd
@cache {
not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
not path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
not method POST
not expression {query} != ''
}
route @cache {
try_files /wp-content/cache/page_enhanced/{host}{uri}/_index_ssl.html /wp-content/cache/page_enhanced/{host}{uri}/_index.html {path} {path}/index.php?{query}
}
php_fastcgi unix//run/php/php8.1-fpm.sock
log {
output file /var/log/forum.access.log {
roll_size 1gb
roll_keep 5
roll_keep_for 720h
}
format json
level DEBUG
}
file_server
tls shuai.zend@qq.com
}