1
Fork 0
mirror of https://github.com/thegeneralist01/config.git synced 2026-12-04 18:56:56 +01:00

thegeneralist(plex): proxy tailscale0 32400 through loopback

This commit is contained in:
TheGeneralist 2026-11-30 23:36:57 +01:00
parent 8be7c15005
commit 17a3ba965c
Signed by: thegeneralist01
SSH key fingerprint: SHA256:pp9qddbCNmVNoSjevdvQvM5z0DHN7LTa8qBMbcMq/R4

View file

@ -93,10 +93,35 @@ in
};
# Allow Plex direct access from the home LAN subnet without exposing 32400 globally.
# tailscale0 is already trusted in modules/linux/tailscale.nix.
# Redirect Tailscale traffic targeting :32400 through a local TCP proxy so Plex
# sees 127.0.0.1 (Loopback) instead of the client's 100.64.0.0/10 Tailscale IP.
networking.firewall.extraCommands = ''
iptables -A nixos-fw -s 192.168.2.0/24 -p tcp --dport 32400 -j nixos-fw-accept
iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32401 2>/dev/null || true
iptables -t nat -A PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32401
'';
networking.firewall.extraStopCommands = ''
iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32401 2>/dev/null || true
'';
systemd.sockets.plex-tailscale-proxy = {
description = "Socket for Tailscale Plex loopback proxy";
wantedBy = [ "sockets.target" ];
listenStreams = [ "0.0.0.0:32401" ];
};
systemd.services.plex-tailscale-proxy = {
description = "Proxy Tailscale Plex traffic through loopback";
wants = [ "plex.service" ];
requires = [ "plex-tailscale-proxy.socket" ];
after = [ "plex.service" "plex-tailscale-proxy.socket" ];
serviceConfig = {
ExecStart = "${pkgs.systemd}/lib/systemd/systemd-socket-proxyd -c 1024 127.0.0.1:32400";
DynamicUser = true;
PrivateTmp = true;
NoNewPrivileges = true;
};
};
services.nginx.virtualHosts = {
${domain} = config;