From 0fa98c7283b591ddb794d87a7985bc0c1ed8662c Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sun, 30 Aug 2026 23:29:10 +0000 Subject: [PATCH] Read the client IP from X-Real-IP behind the nginx reverse proxy Since TLS termination moved to nginx, aiohttp's request.remote is nginx's own address on the docker network (172.21.0.1), a private IP that resolve_ip_country() correctly refuses to geolocate. Nginx already forwards the real client address via X-Real-IP (iptv.mrk.ovh.conf); read that first so device IP/country tracking works again. Co-Authored-By: Claude Sonnet 5 --- server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index 3e008a5..a32c53e 100644 --- a/server.py +++ b/server.py @@ -1462,8 +1462,12 @@ def messageReceived(): def connect(sid, environ): # engineio's aiohttp integration hardcodes REMOTE_ADDR to 127.0.0.1; # the real peer address is only available via the underlying aiohttp request. + # Behind the nginx reverse proxy, that peer is nginx itself, so prefer the + # client IP nginx forwards via X-Real-IP (set in iptv.mrk.ovh.conf). aiohttp_request = environ.get('aiohttp.request') - ip_address = aiohttp_request.remote if aiohttp_request else '' + ip_address = '' + if aiohttp_request: + ip_address = aiohttp_request.headers.get('X-Real-IP') or aiohttp_request.remote or '' sio_session_ips[sid] = ip_address print("connect ", sid, ip_address, flush=True)