From 2d7bab16d4afb56e2848fa76ce91f04a2a4368d1 Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Sun, 29 Nov 2026 16:26:09 +0100 Subject: [PATCH] thegeneralist(plex): allow LAN subnet 32400 and mask Tailscale proxy IP --- hosts/thegeneralist/plex/default.nix | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/hosts/thegeneralist/plex/default.nix b/hosts/thegeneralist/plex/default.nix index d9c06da..057f08d 100644 --- a/hosts/thegeneralist/plex/default.nix +++ b/hosts/thegeneralist/plex/default.nix @@ -26,7 +26,9 @@ let locations."/" = { proxyPass = "http://127.0.0.1:32400"; proxyWebsockets = true; - recommendedProxySettings = true; + # Disable per-location recommended headers so they don't overwrite + # the localhost X-Real-IP / X-Forwarded-For override below. + recommendedProxySettings = false; # https://arne.me/blog/plex-on-nixos extraConfig = '' # Some players don't reopen a socket and playback stops totally instead of resuming after an extended pause @@ -47,9 +49,13 @@ let # Buffering off send to the client as soon as the data is received from Plex. proxy_redirect off; proxy_buffering off; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # This vhost only listens on Tailscale (100.108.125.63); present Tailscale + # clients as local loopback so Plex doesn't treat 100.64.0.0/10 as remote. + proxy_set_header X-Real-IP 127.0.0.1; + proxy_set_header X-Forwarded-For 127.0.0.1; proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Server $hostname; proxy_set_header Host $host; ''; }; @@ -86,6 +92,12 @@ in allowedUDPPorts = [ 1900 5353 32410 32412 32413 32414 ]; }; + # Allow Plex direct access from the home LAN subnet without exposing 32400 globally. + # tailscale0 is already trusted in modules/linux/tailscale.nix. + networking.firewall.extraCommands = '' + iptables -A nixos-fw -s 192.168.2.0/24 -p tcp --dport 32400 -j nixos-fw-accept + ''; + services.nginx.virtualHosts = { ${domain} = config; "100.108.125.63" = config;