[英]How to get real client IP directly from nginx
I want to get the final real client IP direct from nginx return, and avoid getting the IP of proxy servers.我想直接从nginx返回得到最终的真实客户端IP,避免得到代理服务器的IP。
The articles I have searched are all something like我搜索过的文章都是这样的
server /client-ip {
...
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
...
}
But this format is for applications to get IP from request.但是这种格式是为了应用程序从请求中获取 IP。
How can it directly return the real client IP when the URL is hit?怎么能在URL命中的时候直接返回真实客户端IP呢? like
喜欢
server /client-ip {
...
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
return "$X-real-ip"
}
But of course, the above format is not working.但是当然,上面的格式是行不通的。 How can I modify the above format to get final client's IP directly without getting proxy server's IP?
如何修改上述格式直接获取最终客户端的IP而不获取代理服务器的IP?
http {
# …
server {
# …
location /client-ip {
return 200 $remote_addr;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.