Record real IP address on using phoenix in the nginx upstream

别说谁变了你拦得住时间么 提交于 2019-12-11 00:09:50

问题


I have an upstreaming phoenix app, like that:

upstream my_app {
    server localhost:3001;
}

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

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

I want to track real IP address, but I don't know how to do it via standard phoenix conn.remote_ip because its always return 127.0.0.1 (because nginx proxies this query to phoenix). How can I fetch real ip address?


回答1:


There is x-forwarded-for header designed especially for that!

# nginx
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# phoenix
conn.get_req_header(conn, "x-forwarded-for")


来源:https://stackoverflow.com/questions/39198323/record-real-ip-address-on-using-phoenix-in-the-nginx-upstream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!