Skip to content

Instantly share code, notes, and snippets.

@peterc
Last active March 16, 2024 11:52
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterc/fef53e6a308d412ab793148a1808977a to your computer and use it in GitHub Desktop.
Save peterc/fef53e6a308d412ab793148a1808977a to your computer and use it in GitHub Desktop.
Caddyfile for running Mastodon – November 2022 edition

Caddyfile (v2+) for Mastodon

nginx? Boo.. Caddy? Yay!

Please note this was not of my own creation. It comes from Naoki Kosaka's https://gist.github.com/yukimochi/bb7c90cbe628f216f821e835df1aeac1

If you are finding your asset / static files are all 404 with this, this can help:

usermod -aG mastodon caddy

Alternatively, you could get Mastodon's Rails process to serve static files itself, but they advise against this for performance reasons.

put.your.domain.here {
@local {
file
not path /
}
log {
output file /var/log/caddy/mastodon.log
}
@local_media {
path_regexp /system/(.*)
}
@streaming {
path /api/v1/streaming/*
}
@cache_control {
path_regexp ^/(emoji|packs|/system/accounts/avatars|/system/media_attachments/files)
}
root * /home/mastodon/live/public
encode zstd gzip
handle_errors {
rewrite 500.html
file_server
}
header {
Strict-Transport-Security "max-age=31536000"
}
header /sw.js Cache-Control "public, max-age=0"
header @cache_control Cache-Control "public, max-age=31536000, immutable"
handle @local {
file_server
}
## If you've been migrated media from local to object storage, this navigate old URL to new one.
# redir @local_media https://yourobjectstorage.example.com/{http.regexp.1} permanent
reverse_proxy @streaming {
to http://localhost:4000
transport http {
keepalive 5s
keepalive_idle_conns 10
}
}
reverse_proxy {
to http://localhost:3000
header_up X-Forwarded-Port 443
header_up X-Forwarded-Proto https
transport http {
keepalive 5s
keepalive_idle_conns 10
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment