Hello, I use OPNSense with the Wireguard plugin at home (192.168.1.0/24). I connect to the home network with my cell phone via Wireguard (WG-opnsense: 10.10.0.1 WG-cellphone 10.10.0.2).
This works perfectly, even with local DNS via adguard routing. For example to immich.example.de (selfhosted).
This also works so far.
However, I would like to block access from the Internet. This also works according to the instructions Caddy: Reverse Proxy — OPNsense documentation . At home in the home network, I can access immich.example.de via caddy. This is not possible from the Internet.
But if I access it from my cell phone via Wireguard, it doesn’t work either. But it should work.
tl;dr
OPNSense and Wireguard working fine, but wg-clients can’t open caddy served website.
2. Error messages and/or full log output:
Cellphone Broswer: ERR_CONNECTION_CLOSED
3. Caddy version:
Actual OPNSense 25.1.a_194 with CaddyPlugin 1.6.3_1
4. How I installed and ran Caddy:
OPNSense in a own router (APU-Router), Caddy via Plugin
edit: I’m solving it half:
I#; using the opnsense plugin AdGuard. If I redirect in adguard immich.example-de to its own opnsense IP (192.168.1.1), than it works?
Is bind (Caddyfile directive) — Caddy Documentation not suitable for this setup? You could configure Caddy to bind to the LAN and WireGuard interfaces rather than trying to match the client IP.
If that’s not doable, considering your configuration (check client IP → reverse proxy allowed clients upstream), we should probably double check something very basic to start with. What client_ip does Caddy actually think those requests are coming from?
For that…
We need the actual logs from Caddy, rather than the error from your mobile device.
The help template you filled out should’ve directed you to the debug option:
Ensuring you’re collecting those logs, making a request, and then posting the resultant logs here should give us a better idea of what might be going on.
Caddy listens on all IP addresses on the OPNsense (any interface).
This means it will also listen on the IP address of any wireguard interface and any local interface. If the allowed IPs in Wireguard allow access to any of these IP addresses, and the Wireguard Firewall rules allow the connection, then it will establish to Caddy.
If the connection closes, its most likely a Wireguard MTU issue. Try to lower the MTU on the Client that connects by lowering the MTU in the Wireguard configuration file of the client.
Hello! Thank you for your help and sorry for the late reply.
The caddy-debug-log is clear (empty).
Maybe this is expected behavior.
Again:
Opnsense with caddy plugin, immich.example.com works inside my network as expected (blocked outside my network).
In my home network, I can browse to immich.example.de or 192.168.1.50.
From my smartphone (connected via wireguard to my home network) immich.example.de doesnt work, but 192.168.1.50.
I also have the opnsense adguard-plugin. If I state there “immich.example.de => 192.168.1.1” than it does work over wireguard.
It seems that the routes for my domain are:
Inside my Home Network:
Browser => opnsense/caddy
Over wireguard: smartphone => wg =>opnsense/adguard => opnsense/caddy.
I don’t understand the logic.
In my mind wireguard ask at first adguard, and not caddy.
On the other hand in my home network, the browser hits at first opnsense/caddy.
I dont understand the logic in opnsense with two plugins adguard and caddy.
Check with a DNS app on the smartphone how example.com resolves when:
Wireguard is enabled
Wireguard is disabled
Since allowed IPs is not 0.0.0.0/0, any traffic that is not on the allowed IPs (10.10.0.0/24 192.168.1.0/24) will be routed to the default gateway of your phone (aka the internet).
This should essentially work if example.com resolves to the external IP of your OPNsense while connected to wireguard. If it does not, now you know where to look.
Thank you!
Its getting hotter
I dont wanna route all my traffic over my homenetwork (0.0.0.0/0 allowed IP).
But…I see 10.10.0.1 is my DNS. This way Im using my adguard via wg.
And the missing link is on opnsense between my wg server service 10.10.0.1 and caddy.
Thats why it works out of the box with adguard but not with caddy.
WG server dns is pointed to 192.168.1.1, but somehow its routes to adguard instead of caddy.
Its an bug in the wg plugin?
I understand now the background. And I can live with the dns rewrite in adguard to caddy.
Thank you very much! @Monviech I really appreache it.