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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
6881839e31
commit
0fa98c7283
@@ -1462,8 +1462,12 @@ def messageReceived():
|
|||||||
def connect(sid, environ):
|
def connect(sid, environ):
|
||||||
# engineio's aiohttp integration hardcodes REMOTE_ADDR to 127.0.0.1;
|
# engineio's aiohttp integration hardcodes REMOTE_ADDR to 127.0.0.1;
|
||||||
# the real peer address is only available via the underlying aiohttp request.
|
# 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')
|
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
|
sio_session_ips[sid] = ip_address
|
||||||
print("connect ", sid, ip_address, flush=True)
|
print("connect ", sid, ip_address, flush=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user