python3 aiohttp server can't get real ip behind nginx python3 aiohttp server can't get real ip behind nginx nginx nginx

python3 aiohttp server can't get real ip behind nginx


I solve it with

host = request.headers.get('X-FORWARDED-FOR',None)


I think peername is always the IP of the directly connected machine. The IP of the original client is only accessible via HTTP headers, in this case set in the nginx configuration via proxy_set_header X-Real-IP $remote_addr;.

If you would like to get the original client IP, try

host = request.remote

See web_request.py