问题
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