Flask使用Nginx反向代理后依然获取用户真实IP

nginx配置的location中添加

proxy_set_header X-Real-IP $remote_addr;

Flask代码中添加

try:
    _ip = request.headers["X-Real-IP"]
    if _ip is not None:
        ip = _ip
except Exception as e:
    print(e)

你可能感兴趣的:(python,python,nginx)