I was following along with the below link to try and setup matrix, and wanted to use tailscale to expose the matrix server to my tailnet. I’ve heard it should “just work”, and it wasn’t, so I tried adding in caddy to the mix which also “should just work”, but doesn’t. I can ping the server, but it seems like https certs aren’t being handled? I’ve set tailscale.service.permitCertUid = "caddy" however it still doesn’t automatically handle certs for me. Am I missing something here? I can connect to it fine, but I don’t get an https connection, and when trying to connect using the element android app, it gets an ssl error.
Thanks for the config! I’ve got it building but still can’t get a secure connection to the server.
I put my tailnet ***.ts.net into the tld option, and tried connecting to port 80, 443, no port, adding conduit (6167) to the config and connecting to that, but none of them can get a secure connection.
I believe that caddy obtains the certificates from LetsEncrypt and doesn’t allow direct access to port 80, since after the certificate generation is complete, it automatically forwards all requests to 443. Also you can only access the port through the domain: ..ts.net.
You need to modify the caddy (Caddyfile) config a bit more to not automatically forward/upgrade the ports you want to access.
Sorry if this isn’t what you’re after–there are a few ways to solve this after all–but I took the route of installing caddy-tailscale as a Caddy plugin. This lets me do something like:
One problem I have with this setup is that the caddy systemd unit sometimes hangs and times out. I haven’t fully figured out if this only happens when provisioning a new device, but either way, ctrl-c’ing out of the rebuild and systemctl restart caddy seems to get things unstuck, including finishing the rebuild I thought I’d killed. If you figure out what’s up with this, I’d certainly appreciate the fix. Could be it’s fixed in newer Caddy/plugin versions but I haven’t tried bumping those yet. I don’t much like killing rebuilds but they seem to pick up like nothing went wrong when caddy is restarted manually.
Otherwise, no, I’m not sure how to proxy from Tailscale magic domain names to something local without explicitly using either the tailscale binary or a plugin/integration of some sort.
I’m still working this out (I suck at nixlang so its always a nightmare figuring out how to get stuff where it needs to be), but it seems like you no longer need that flake as it was merged into nixpkgs: https://github.com/NixOS/nixpkgs/pull/358586
I also tried with audiobookshelf on port 8000 just to see if I could get anything to work, but it doesn’t. I can confirm caddy is working using their hello world example, but all the tailscale plugin seems to do is cause timeouts when starting the caddy service. The status is “stopped; run ‘tailscale up’ to log in”