【问题标题】:Record real IP address on using phoenix in the nginx upstream在nginx上游记录使用phoenix的真实IP地址
【发布时间】:2016-08-31 01:16:50
【问题描述】:

我有一个上游的凤凰应用,像这样:

upstream my_app {
    server localhost:3001;
}

server {
    root /var/www/my_app/priv/static;
    listen 80;

    location / {
        proxy_pass http://my_app;
    }
}

我想跟踪真实的 IP 地址,但我不知道如何通过标准 phoenix conn.remote_ip 进行跟踪,因为它总是返回 127.0.0.1(因为 nginx 将此查询代理到 phoenix)。如何获取真实IP地址?

【问题讨论】:

    标签: elixir phoenix-framework


    【解决方案1】:

    有专门为此设计的 x-forwarded-for 标头!

    # nginx
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
    # phoenix
    conn.get_req_header(conn, "x-forwarded-for")
    

    【讨论】:

      猜你喜欢
      • 2014-11-02
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-29
      • 1970-01-01
      相关资源
      最近更新 更多