在我的 Rails 示例中,我还让每个应用程序运行在不同的端口上,所以 foo 在 localhost:3000 上,bar 在 localhost:3001 上,所以 foo 将通过 访问 bar 上的 urlhttp://192.168.50.51:3001/some_urlLet's say I make two vagrant boxes, foo and bar:$ mkdir -p foo bar$ pushd foo; vagrant init hashicorp/precise32; vagrant up; popd$ pushd bar; vagrant init hashicorp/precise32; vagrant up; popdNow let's say I start an HTTP server on foo:$ cd foo$ vagrant ssh -c 'python -m SimpleHTTPServer 8080My question is, how can I get bar to communicate (e.g. via curl) with foo?$ cd bar$ vagrant ssh -c 'curl http://????' 解决方案 Although the question does not make it clear, I think this older question is asking:if the *same* development machine is running two vagrant instances, how can an app running onfoofetch data from a url onbar`.If so, I ran into this recently for my two Rails apps(each running in a separate vagrant instance on the same development machine).The two-part 'trick' if foo wants to fetch data from bar, is:1) each Vagrant files needs a line:config.vm.network :private_network, ip: PVT_NETWORKwhere PVT_NETWORK is a local IP, is different for each Vagrant file, and probably needs to be in the same subnet. For example PVT_NETWORK might be 192.168.50.50 (foo) and 192.168.50.51 (bar)2) foo accesses bar via the PVT_NETWORK IP address not the "real" IP you would use with a web browser.In my Rails example, I also have each app running on a different port, so foo is on localhost:3000 and bar is on localhost:3001, so foo would access a url on bar via http://192.168.50.51:3001/some_url 这篇关于如何让两个流浪盒子互相交谈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-12 16:56