2017-04-21 168 views
1

我有一個可編譯的/運行在流浪漢上的彈簧應用程序,並聽取localhost:8080(流浪者內部)。Vagrant:Forwarded Ports does not work

這是我Vagrantfile

Vagrant.configure("2") do |config| 
config.vm.box = "ubuntu/xenial64" 
config.vm.network :forwarded_port, guest: 80, host: 9000, host_ip: "127.0.0.1" 
config.vm.provision :shell, path: "bootstrap.sh" 
end 

現在我想通過localhost:9000從主機訪問我的Spring的應用程序。

無論如何forwarded_port線不起作用,我真的不知道爲什麼?

我在流浪文件中有什麼變化?

SOLUTION:

隨着Vagrantfile低於它爲我工作。

Vagrant.configure("2") do |config| 
config.vm.box = "ubuntu/xenial64" 
config.vm.network "private_network", ip: "192.168.33.10" 
config.vm.provision :shell, path: "bootstrap.sh" 

config.vm.provider "virtualbox" do |v| 
     v.destroy_unused_network_interfaces = true 
     v.memory = 2048 
     v.cpus = 4 
end 
end 

回答

2

,因爲應用程序是在localhost聽它不工作。

使應用程序在常規界面上偵聽。如果不是Vagrant界面,您可能還需要添加guest_ip

config.vm.network :forwarded_port, guest: 80, guest_ip: "xxx.xxx.xxx.xxx", host: 9000, host_ip: "127.0.0.1 
+0

你能更具體嗎? ..我是全新的所有這些僞服務器的東西 – SteveOhio

+0

我不能更具體,因爲你不是。顧名思義,Localhost僅用於本地連接。 – techraf

+0

所以我必須讓spring-app聽'guest_ip'? – SteveOhio

0

如果在虛擬機中運行你的春天應用程序的確聽其本地端口8080,你想從你的主機訪問該應用程序爲http://localhost:9000/,然後在你的Vagrantfile行應該是:

config.vm.network :forwarded_port, guest: 8080, host: 9000 

,即你有一個錯字上的來賓指定端口80,而不是8080

你也許並不需要指定諸如host_ip或guest_ip任何其他參數。

+0

我找到了解決方案,並將其添加到我的問題.. thx爲您的努力 – SteveOhio