本文介绍了在Nginx上游使用phoenix记录真实IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个上游的phoenix应用程序,像这样:
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;
}
}
我想跟踪真实的IP地址,但是我不知道如何通过标准的phoenix conn.remote_ip
来实现,因为它总是返回127.0.0.1
(因为nginx
将此查询代理为phoenix).如何获取真实的IP地址?
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?
推荐答案
有专门为此目的设计的x-forwarded-for
标头!
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")
这篇关于在Nginx上游使用phoenix记录真实IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!