0
votes

I'm using a vagrant trusty64 box with nginx, flask, gunicorn and port forwarding is not working as expected

In the vagrant file, I have:

config.vm.network "forwarded_port", guest: 8090, host: 3100
config.vm.network "private_network", ip: "10.10.1.10"

On the box, I have run:

gunicorn myprj:app -b 10.10.1.10:8090 

find nothing on host machine with http://10.10.1.10:3100

trying curl -v http://10.10.1.10:3100 gives the following output:

connect to 10.10.1.10 port 3100 failed: Connection refused

Reachable with guest port on host machine http://10.10.1.10:8090

I am new to the vagrant, did I miss/mess to Vagrant file.

Complete Vagrant file:

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.box_check_update = false
  config.vm.network "forwarded_port", guest: 8090, host: 3100
  config.vm.network "private_network", ip: "10.10.1.10"
  config.vm.synced_folder ".", "/vagrant_data"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "1024"
    vb.name = "lopamudra_dev"
  end
  config.vm.provision "shell", inline: <<-SHELL
    # Upgrading the environment
    apt-get update
    apt-get upgrade
    # Installing nginx + uwsgi + flask
    apt-get install -y python-pip python-dev nginx
    pip install uwsgi flask gunicorn  
  SHELL
end
1
does 10.10.1.10:8090 work? - jonhid
yes, it working with port 8090. It's weird, I am forwarding 8090 to 3100 right ? - user9623444

1 Answers

0
votes

You are forwarding container 8090 to hostIP:3100 (localhost:3100) At the same time you are creating a IP to access your container with 10.10.1.10 and you container has 8090 exposed, thats why you can acces it on 10.10.1.10:8090

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port

config.vm.network "forwarded_port", guest: 8090, host: 3100

# Create a private network, which allows host-only access to the machine
# using a specific IP.

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