Amazon Elastic Beanstalk - 获取访问者 IP 地址(python) [英] Amazon Elastic Beanstalk - get visitor IP address (python)
问题描述
我的应用程序是用 python 和 bottle 框架开发的.我正在使用以下代码片段来获取页面访问者的 IP 地址:
My application is developed in python and the bottle framework. I am using following code snippet to get IP address of visitors to the page:
user_ip = bottle.request.environ['REMOTE_ADDR']
它在我的本地机器上运行良好,但是,在部署到 AWS Beanstalk 实例之后,我想我正在获取负载均衡器 IP,因为 user_ip 读取的内容类似于 10.48.95.234.
It works fine on my local machine, however, after deployment to the AWS Beanstalk instance, I think I am getting the load balancer IP, as the user_ip reads something like 10.48.95.234.
我的想法正确吗?如果有,有什么办法可以获取到真实访客的ip地址?
Is my thinking correct? If so, is there any way to obtain real visitor's ip address?
推荐答案
您正确的是,您获得的 REMOTE_ADDR
值适用于 ELB.
You are correct that the REMOTE_ADDR
value you are getting is for the ELB.
您通常需要在请求中查找 X-Forwarded-For
标头.ELB 将插入此标头以告知您最终客户端 IP 地址.
You would typically need to look for the X-Forwarded-For
header in the request. The ELB will insert this header to let you know the end client IP address.
这篇关于Amazon Elastic Beanstalk - 获取访问者 IP 地址(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!