流浪港端口转发客人端口和主机端口混乱

时间:2018-04-10 07:57:20

标签: vagrant portforwarding vagrantfile

我使用带有trusty64的流浪nginx, flask, gunicorn框并且端口转发无法按预期工作

在vagrant文​​件中,我有:

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

在盒子上,我跑了:

gunicorn myprj:app -b 10.10.1.10:8090 

使用http://10.10.1.10:3100

在主机上找不到任何内容

尝试curl -v http://10.10.1.10:3100会得到以下输出:

connect to 10.10.1.10 port 3100 failed: Connection refused

  

可通过主机http://10.10.1.10:8090

上的访客端口访问

我是流浪汉的新手,我错过了/乱七八糟的文件。

完成Vagrant文​​件:

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 个答案:

答案 0 :(得分:0)

您正在将容器8090转发给hostIP:3100(localhost:3100)   同时你创建一个IP来访问10.10.1.10的容器,你的容器有8090暴露,这就是你可以在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"