-
-
Save yukimochi/bb7c90cbe628f216f821e835df1aeac1 to your computer and use it in GitHub Desktop.
https://yourdomain.example.com/ { | |
log / /var/log/caddy/mastodon.log "{combined}" { | |
rotate_age 90 | |
} | |
root /home/mastodon/live/public | |
gzip | |
header / { | |
Strict-Transport-Security "max-age=31536000" | |
} | |
header /sw.js Cache-Control "public, max-age=0" | |
header /emoji Cache-Control "public, max-age=31536000, immutable" | |
header /packs Cache-Control "public, max-age=31536000, immutable" | |
header /system/accounts/avatars Cache-Control "public, max-age=31536000, immutable" | |
header /system/media_attachments/files Cache-Control "public, max-age=31536000, immutable" | |
errors { | |
* 500.html | |
} | |
rewrite { | |
if {path} is / | |
to /proxy{path} | |
} | |
rewrite { | |
if {path} not_has /api/v1/streaming | |
to {path} /proxy{path} | |
} | |
proxy /proxy localhost:3000 { | |
without /proxy | |
transparent | |
websocket | |
} | |
proxy /api/v1/streaming localhost:4000 { | |
transparent | |
websocket | |
} | |
tls [email protected] | |
} |
{ | |
email [email protected] | |
} | |
https://yourdomain.example.com { | |
@local { | |
file | |
not path / | |
} | |
@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 | |
log { | |
output file /var/log/caddy/mastodon.log | |
} | |
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 | |
} | |
} | |
} |
Woah thank you, works perfectly out of the box for me now :)
@yukimochi would you mind to post your complete mastodon config? I am unable to set up this correctly (I already use caddy with other docker containers in my server, but mastodon is particularly hard for me)
Did you ever get this working correctly?
For reference: my Caddyfile for Mastodon is online at https://blog.riemann.cc/digitalisation/2022/02/09/mastodon-setup-with-docker-and-caddy/
One huge pro tip here is to run something like usermod -aG mastodon caddy
.. mine was refusing to load assets and static files and it took me ages to figure out it was a permissions issue :-)
@rnaff I've put it up at https://gist.github.com/peterc/fef53e6a308d412ab793148a1808977a - I think it's pretty much the same as the one here.
FYI, line 14 on v2, seems incorrect. Its working for most clients, but certain libraries seem to be throwing strange errors (as they sometimes lack the last /
on the end of the URL).
Needs changing from path /api/v1/streaming/*
to path /api/v1/streaming*
@yukimochi would you mind to post your complete mastodon config? I am unable to set up this correctly (I already use caddy with other docker containers in my server, but mastodon is particularly hard for me)