【问题标题】:How to pass the remote IP to a proxied service? - Nginx如何将远程 IP 传递给代理服务? - Nginx
【发布时间】:2011-06-20 07:10:51
【问题描述】:

我在 127.0.01:8000 的 localhost 中运行服务

我正在使用以下方式进行代理:

proxy_pass http://127.0.0.1:8000;

问题是我需要将用户的 IP 地址传递给服务。


有什么想法吗?

【问题讨论】:

    标签: python django ubuntu nginx gevent


    【解决方案1】:

    我通过设置自定义标头将真实 IP 发送到 django:

    proxy_set_header X-Real-IP $remote_addr;

    request.META 中提供了这些标头

    【讨论】:

    • 通过request.META['HTTP_X_REAL_IP']从 Django 访问。
    • 我确认 eli_mach 的答案和评论都是正确的。
    • 对我有用,谢谢。以下是我从 Pyramid (Python) 中获取值的方法:if 'X-Real-IP' in request.headers and request.headers['X-Real-IP']: ip_address = request.headers['X-Real-IP']
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 2022-01-14
    • 2015-11-15
    • 2013-09-13
    • 2014-04-06
    • 2021-09-09
    • 2023-03-24
    • 2016-09-07
    相关资源
    最近更新 更多