vagrant port forwarding guest 和 host 端口搞砸了
vagrant port forwarding guest and host port messed up
我正在使用带 nginx, flask, gunicorn
的 vagrant trusty64
框,但端口转发未按预期工作
在 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
Reachable with guest port on host machine http://10.10.1.10:8090
我是vagrant的新手,我miss/mess到Vagrant文件了吗
完整的 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
您正在将容器 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"
我正在使用带 nginx, flask, gunicorn
的 vagrant trusty64
框,但端口转发未按预期工作
在 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
Reachable with guest port on host machine
http://10.10.1.10:8090
我是vagrant的新手,我miss/mess到Vagrant文件了吗
完整的 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
您正在将容器 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"