Vagrant: Getting connecting clients real ip

别说谁变了你拦得住时间么 提交于 2021-02-10 20:17:38

问题


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.

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

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

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

Thanks!


回答1:


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.

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



来源:https://stackoverflow.com/questions/34365760/vagrant-getting-connecting-clients-real-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!