Vagrant host port is ignored

In my Vagrantfile I have a definition of my development machine with a private ip network 192.168.33.10 and a forwarded port "guest = 80, host = 8888", but when I start my stray environment and try to start curl -i 192.168.33.10:8888 I get the error message 'Could not connect to 192.168.33.10:8888; connection refused', but when I try to connect to 192.168.33.10:80, everything is fine.

My vagrantfile:

Vagrant::configure("2") do |config| config.vm.box = "precise32" config.vm.define :web do |www| www.vm.hostname = "apache" www.ssh.max_tries = 10 www.vm.network :forwarded_port, guest: 80, host: 8888 # Apache port www.vm.network :private_network, ip: "192.168.33.10" www.vm.synced_folder "www", "/var/www", :extra => 'dmode=777,fmode=777' end end 

Why is this happening? brandy ignores the forwarded port?

+4
source share
1 answer

By default, Vagrant Boxes use NAT mode, which means that guests are behind the router engine ( VirtualBox Networking between the host and the guest ), which transparently displays traffic from the virtual machine. Guests are invisible and inaccessible to the host.

To do this, we need port forwarding. Otherwise, services running on the guest page are available.

In your case, you use a Private network , the guest will be assigned a private IP address, to which the host ONLY can access, which is 192.168.33.10 .

The correct way to access a website hosted on a guest computer is β†’ http://192.168.33.10 from the host.

You have port forwarding feature in Vagrantfile

 www.vm.network :forwarded_port, guest: 80, host: 8888 # Apache port 

It forwards guest port 80 to your 8888 host. Since you are NOT using NAT mode , I am sure it will be ignored. Try curl -Is http://localhost:8888 .

NOTE. Even if it still works, you must access the network through => http://localhost:8888/ from your host.

+6
source

Source: https://habr.com/ru/post/1492635/


All Articles