-
-
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 | |
} | |
} | |
} |
Which of the two is current? Do they have different use-cases?
.caddy1 is for Caddy v1.x.x, .caddy2 is for Caddy v2.x.x.
Thanks! I have set up my instance as per https://docs.joinmastodon.org/admin/install and added your caddy2 configuration. Unfortunately I get an error screen and am not sure how to get more useful debug output to find out whether the issue is the caddy config or in my setup.
https://caddy.community/t/trying-to-use-caddy-for-mastodon-having-trouble-translating-caddyfile-from-v1-to-v2/8256/10
Seems like a rewrite
to the proxy is necessary - if I visit /about
it works, but there is no automatic redirection :/
@mdszy if you happen to be the same person who posted on the caddy forum - do you still have an active working config?
@mdszy if you happen to be the same person who posted on the caddy forum - do you still have an active working config?
hi it's me (that's my old github but apparently the email still got sent, whodathunk)
this is the config that i currently use that works, obv with a different domain but ya know
example.com {
@try_masto {
file
}
root * /home/mastodon/glitch/public
handle @try_masto {
file_server *
}
handle /api/v1/streaming* {
reverse_proxy * localhost:4000
}
handle {
reverse_proxy localhost:3000
}
encode gzip
header {
Strict-Transport-Security "max-age=31536000;"
}
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"
handle_errors {
root * /home/mastodon/glitch/public
rewrite 500.html
file_server
}
}
media.example.com {
rewrite * /examplecom{uri}
reverse_proxy https://cdn.xyz.abc
}
@szyszyszyszy thanks for chiming in :)
Is the media-domain related to mastodon as well?
Otherwise the config seems to be the same as in that thread. Do you use the latest version of Mastodon (v3.3.0)?
With either your file or the one from the gist I can login and visit subpages like about, explore, even my account settings. But the homepage, the most important part, does not work appropriately.
@szyszyszyszy @yukimochi can anyone help me? I'm kinda stuck :/
Please, I'd really like to use caddy ☹
Dear @xerus2000 , sorry for late response.
I checked new Caddyfile specification and behavior.
Caddy version 2.2.0>= has different behavior for file
matcher with /
path.
So, I added not path /
in line 8.
Please use this instead. Have a good caddy life.
@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)
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*
Will this work for the latest version of Mastodon? Thanks!