Howdy @sundervart, welcome to the Caddy community.
I found it was also useful to peek at the Seafile docs on the recommended nginx configuration, to get an understanding of what they’re doing on both servers. It’s pretty cool because they actually explain what the important sections do:
The most interesting parts of this configuration are:
listen 80; The port Nginx listens to server_name _; The 'name' of the virtual server server_tokens off; Nginx does not reveal its version number to make life more difficult for attackers location /seafile proxy for seahub (!) location /seafhttp proxy for seafile (!) location /seafmedia static content of Seafile Server location /seafdav proxy for seadav access_log and error_log Nginx log files
We don’t care about listeners, server names or tokens.
First up, we see that in nginx they proxy /seafile
locally to 127.0.0.1:8000
, although you proxy the web root /
. This is the easiest one.
Proxies requests to one or more backends with configurable transport, load balancing, health checking, header manipulation, and buffering options.
—reverse_proxy (Caddyfile directive) — Caddy Documentation
It’s as simple as this:
reverse_proxy http://127.0.0.1:8000
Next, we can see that they proxy /seafhttp
and strip the prefix, which we do in Caddy with handle_path
:
Same as the
handle
directive, but implicitly strips the matched path prefix.
—handle_path (Caddyfile directive) — Caddy Documentation
handle_path /seafhttp* {
reverse_proxy http://127.0.0.1:8082
}
They take /seafmedia
, rewrite to /media
, and then serve files from /opt/seafile/seafile-server-latest/seahub
. We can use handle_path
again to remove the old prefix and rewrite
to add the new one, set the root
, then add a file_server
.
Rewrites the request internally. A rewrite changes some or all of the request URI.
—rewrite (Caddyfile directive) — Caddy Documentation
A static file server. It works by appending the request’s URI path to the site’s root path.
—file_server (Caddyfile directive) — Caddy Documentation
Like so:
handle_path /seafmedia* {
rewrite * /media{uri}
root * /opt/seafile/seafile-server-latest/seahub
file_server
}
They also have a /seafdav
path they proxy to http://127.0.0.1:8080
. Another easy one:
reverse_proxy /seafdav* http://127.0.0.1:8080
Logging can be as easy or as complicated as you want with the log
directive. You don’t appear to have logging in Apache configured but here’s how you’d do it based on Seafile’s nginx default:
Enables and configures HTTP request logging (also known as access logs).
—log (Caddyfile directive) — Caddy Documentation
log {
output file /var/log/caddy/seafile.access.log
# Uncomment below if you prefer common log format:
# format single_field common_log
}
Add it all together and add some handle
blocks to ensure each path is exclusive to each other and neat, and we get something like this that looks suspiciously nginx-like, actually:
example.com {
handle {
reverse_proxy http://127.0.0.1:8000
}
handle_path /seafhttp* {
reverse_proxy http://127.0.0.1:8082
}
handle_path /seafmedia* {
rewrite * /media{uri}
root * /opt/seafile/seafile-server-latest/seahub
file_server
}
handle /seafdav* {
reverse_proxy http://127.0.0.1:8080
}
log {
output file /var/log/caddy/seafile.access.log
}
}
Although I think it looks a bit neater myself!