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)