How can you access a virtual machine using a private Vagrant network on different ports?

I am starting a private Vagrant network with the specified IP address and hostname. I can currently access the http version on port 80, but I would also like to have access to it on port 8080.

I added something like this:

config.vm.network :forwarded_port, guest: 80, host: 8080, auto_correct: true

But, when I visit my site on port 8080, I get a page error message. Port 80 is still running. how can I correctly access my virtual machine on another port if the forwarded port does not work for a private network?

+4
source share
2 answers

, NAT ( VirtualBox NAT), .

, IP- 8080, 8080, iptables .

.

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

+1

, , Vagrantfile, -.

Vagrant.configure("2") do |config|

  config.vm.hostname = "web"

  config.vm.network :private_network, ip: "192.168.33.10"

  config.vm.network :forwarded_port, host: 3000, guest: 3000  
end

Vagrant site.

+1

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


All Articles