流浪汉:获得连接客户端的真实IP [英] Vagrant: Getting connecting clients real ip

查看:82
本文介绍了流浪汉:获得连接客户端的真实IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Apache + Flask网站,在基本的Vagrant + VirtualBox环境中运行.我可以通过127.0.0.1:8080访问我的网站.

I have a simple Apache+Flask website running inside a basic Vagrant+VirtualBox environment. I can access my site fine at 127.0.0.1:8080.

问题&问题是,如何配置Vagrant将真实客户端的IP地址传递给Apache + Flask?

The question & problem is, how do I configure Vagrant to pass the real clients IP address to Apache+Flask?

request.remote_addr始终返回10.0.2.2,无论从我的LAN内部连接什么客户端.

request.remote_addr always returns 10.0.2.2 no matter what client is connecting from within my LAN.

例如,运行Vagrants IP的计算机为192.168.1.5.从客户端(即局域网中IP为192.168.1.7的另一台笔记本电脑)访问@ 192.168.1.5:8080的站点,但是192.168.1.7不是vagrant/flask + apache中的remote_addr,始终为10.0.2.2

For example the machine running Vagrants IP is 192.168.1.5. From a client i.e. another laptop on my LAN with IP of 192.168.1.7, would hit the site @ 192.168.1.5:8080, but 192.168.1.7 is not the remote_addr in vagrant/flask+apache, its always 10.0.2.2

谢谢!

推荐答案

最简单的方法是桥接网络.虚拟机将在您的(外部)网络中收到一个IP地址,例如192.168.1.10.

The most easy way to do that would be a bridged network. The VM will receive an IP address in your (outside) network, e.g. 192.168.1.10.

请参见 https://docs.vagrantup.com/v2/networking/public_network.html关于如何配置它.

See https://docs.vagrantup.com/v2/networking/public_network.html on how to configure that.

这篇关于流浪汉:获得连接客户端的真实IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆