Getting Unifi devices working through Caddy

1. Caddy version (caddy version):

v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

2. How I run Caddy:

a. System environment:

Ubuntu 18.04.4 LTS, systemd

b. Command:

systemctl start caddy

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

File can be found here: https://bin.alexsguardian.net/raw/amokaledaq I tried posting it here but due to commented out sections the formatting on here was messed up and wasnt inside a blockquoute making it hard to read.

3. The problem I’m having:

Trying to get Unifi devices to communicate to the controller through Caddy. I was able to get a USG3 to work but a US-8 switch and two APs are refusing to connect.

The switch did communicate at least once but after that its been disconnected (green bar shows it received CPU stats)

4. Error messages and/or full log output:

Log file is extremely long horizontal so: https://bin.alexsguardian.net/raw/imingapuci

5. What I already tried:

Currently have the Unifi STUN server forwarded on port 3478 as per docs but not sure what else to do. Caddyfile comments can show what I tried but with CaddyV2 I’m still trying to learn the proper way to do things.

Also tried adding a reverse_proxy section for /wss for websockets but it didnt work either and caused a ton of console errors in the browser.

6. Links to relevant resources:

Docker container I’m using: Docker Hub (also using default port setup from image)

I checked the Unifi server log and it defiantly has something todo with websockets but not sure if that is the only problem. All devices have the correct Inform URL set so they should hopefully light up and connect as soon as I can get this config fixed.

For code formatting, use ``` on lines before and after your config. You did it correctly with your service file!

I’m not certain but I think your services might be TCP services rather than HTTP. Caddy by default is an HTTP proxy. For TCP proxying you’ll need to wait for GitHub - mholt/conncept: Project Conncept: A layer 4 app for Caddy that multiplexes raw TCP/UDP streams to be released or sponsor @matt for it to get early access!

I’m just on my phone now so it’s a bit harder to investigate further, and I have no experience with Unifi devices.

Your logs don’t look to have any useful information. All the requests in your logs returned status 200, which looks good. We’d need your Caddy stdout logs which might have more information. You can run journalctl -u caddy to see those logs since you’re running with systemd.

Another note — in your Caddyfile, you have the following

header / {
	...
}

This will only match requests to the root of your site. I think you want to remove the / to make it match all requests.

Yeah I tried the ``` but it wasn’t formatting correctly. Hence why I linked it instead.

Cool so this will sit alongside Caddy HTTP then?

I’ll drop that / from my header, thanks!

I’m a goof. Here’s the log from journalctl -u caddy. Log is rather large and will take a bit to load: https://bin.alexsguardian.net/raw/yrehapucot

The log perms were fixed so disregard those.

This topic was automatically closed after 30 days. New replies are no longer allowed.