Vagrant:端口转发工作奇怪

时间:2017-08-04 11:51:40

标签: vagrant

我的Vagrantfile中有这个:

web.vm.network "private_network", ip: "192.168.33.20"
web.vm.network "forwarded_port", guest: 80, host: 8080

但在我的Mac主机上,我可以使用web访问192.168.33.20:80虚拟机,但不能访问192.168.33.20:8080

为什么这不按预期工作?

1 个答案:

答案 0 :(得分:4)

vagrant Port forwarding is used if you dont have static IP and you want to reach a specific port for a process bound to this specific port running on the VM, so you will access it using http://localhost:8080 and it will forward to port 80 on the VM.

When you have a static IP, you reach directly the network interface to this VM so it tries to connect you on the port 8080 directly in the VM, if you dont have anything running there, it wont show up.

Rules: if you use static IP (wether private or public network) you dont need port forwarding