I am still very new to Caddy. I have my new server all setup and working with a simple sample site. While everything is working, I was hoping to get some feedback on my Caddyfile setup. I am sure that you all are much more proficient at this than I am.
I created a bunch of reusable snippets that I could use with any domain hosted on the server. I also externalized that configs for each domain so that its easy to manage each website config.
Here is my Caddyfile:
{
email {env.EMAIL}
acme_dns cloudflare {env.CLOUDFLARE_CHALLENGE}
order git before respond
git {
repo aspecthq.com {
base_dir /var/www/aspecthq.com
url git@github.com:joeworkman/aspecthq.com.git
branch master
auth key /var/www/ssh/id_ed25519 no_strict_host_key_check
}
}
}
#----------------
# Snippets
#----------------
(logroll) {
roll_size 3MiB
roll_keep 5
roll_keep_for 48h
}
(errors-rewrite) {
rewrite * /404.html
file_server
}
(errors-basic) {
handle_errors {
respond "{http.error.status_code} {http.error.status_text}"
header {
Content-Type "text/plain; charset=utf-8"
}
}
}
(webhook) {
@webhook {
method POST
path /update
}
}
(php81) {
@php {
path *.php
}
route @php {
php_fastcgi unix//run/php/php8.1-fpm.sock
}
encode gzip zstd
file_server
push
}
(www-redirect) {
redir https://www.{host}{uri}
}
#----------------
# Import Sites
#----------------
import /etc/caddy/aspecthq.com.caddy
Caddy file for site config (aspecthq.com.caddy imported above)
aspecthq.com {
import www-redirect
}
www.aspecthq.com {
import errors-basic
log {
output file /var/log/caddy/aspecthq.com.access.log {
import logroll
}
}
import webhook
route @webhook {
git update repo aspecthq.com
}
root * /var/www/aspecthq.com/aspecthq.com
import php81
}
I would love it if there was some way to get the git repo configs into my site specific config file. I could not think of a way to do this though.
I added a route specifically for php files so that only they get sent to php_fastcgi. Does this makes sense to do this? My thinking was why send everything when I know only php requests should go there.