Hi,
I handcrafted my Caddyfile, but I’m quite sure there could be ways to improve it, make it shorter or less verbose.
{
email myemailhere
default_sni removed
key_type p384
}
(globalOptions) {
log {
output file /var/log/caddy/access.log
format json
}
header {
Strict-Transport-Security "max-age=63072000"
X-Content-Type-Options nosniff
X-Frame-Options "DENY"
X-XSS-Protection "1; mode=block"
Content-Security-Policy "upgrade-insecure-requests"
Referrer-Policy no-referrer-when-downgrade
Cache-Control "public, no-cache, max-age=0"
}
handle_errors {
respond "{http.error.status_code} {http.error.status_text}"
}
encode gzip zstd
tls myemailhere
}
(webp) {
@acceptWebpJpg {
header Accept image/webp*
path *.jpg
}
handle @acceptWebpJpg {
try_files {path}.jpg {path}.webp
}
@acceptWebpJpeg {
header Accept image/webp*
path *.jpeg
}
handle @acceptWebpJpeg {
try_files {path}.jpeg {path}.webp
}
@acceptWebpPng {
header Accept image/webp*
path *.png
}
handle @acceptWebpPng {
try_files {path}.png {path}.webp
}
}
domain.dev, domain.me, www.domain.dev, www.domain.me {
root * /www/domain
file_server browse
file_server /grabs/*
import globalOptions
}
paste.domain.dev, paste.domain.me {
reverse_proxy localhost:2345 {
header_up Host {http.reverse_proxy.upstream.hostport}
header_up X-Real-IP {http.request.remote.host}
}
import globalOptions
}
droppy.domain.dev, droppy.domain.me {
reverse_proxy localhost:8989 {
header_up Host {http.reverse_proxy.upstream.hostport}
header_up X-Real-IP {http.request.remote.host}
}
import globalOptions
}
flood.domain.dev, flood.domain.me {
reverse_proxy localhost:3000 {
header_up Host {http.reverse_proxy.upstream.hostport}
header_up X-Real-IP {http.request.remote.host}
}
import globalOptions
}
domain2.sx, domain3.sx, www.domain2.sx, www.domain3.sx {
root * /www/domain2
file_server
import webp
import globalOptions
}
domain4.fr, domain5.com, www.domain4.fr, www.domain5.com {
root * /www/domain4
file_server
import webp
import globalOptions
}
I have removed domain names and emails, but nothing is lost by not having those here
I’m concerned with the following:
- The webp snippet. I implented this in the Caddyfile to reproduce what I had in my nginx config file. The intent is to serve to clients that have image/webp in their Accept header the image in webp format. If they can accept webp, we send the webp image instead of the jpg/png they requested. On disk, the file would be image.png.webp. It currently works, but I feel like it’s too many lines for a simple thing. If there was a way to OR inside the match block, that could be easier to implement.
- Having to add www.domain to the sites. Before Caddy, I had a wildcard certificate from LE. Now, since Caddy won’t behave nicely with nsupdate, I’m settling for the TLS challenge. I don’t think there is a better way to do this, but if there is, I’m all ears.
Any other suggestions or tips is appreciated. Writing a Caddyfile to replace a nginx server is difficult, as there are not many examples around. I would love your input