无法从 Vagrant 访问 Google Cloud SDK for Python 的本地开发服务器
Unable to access local development server of Google Cloud SDK for Python from Vagrant
我 运行 在 Vagrant box 中连接本地开发服务器并尝试在 Chrome(主机)中打开它。但是它无法在主机中打开。使用 curl
on localhost:7000 在来宾机器 returns HTML 的内容。这是我的 Vagrant 文件
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.provision :shell, path: "setup_dev_env.sh"
config.vm.box_check_update = false
config.vm.network "forwarded_port", guest: 7080, host: 7080, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 7000, host: 7000, host_ip: "127.0.0.1"
config.vm.synced_folder "SOME_PATH", "/home/vagrant/code"
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.memory = "4096"
end
end
向运行服务器(来宾计算机)发出的命令:
python /home/vagrant/code/google-cloud-sdk/platform/google_appengine/dev_appserver.py PATH_TO_app.yaml --port=7080 --admin_port=7000 --datastore_path=~/BLAH.db
您需要在运行您的命令(https://cloud.google.com/appengine/docs/standard/python3/tools/local-devserver-command)
时添加以下内容
--host=...
The host address to use for the server. You may need to set this to be able to access the development server from another computer on
your network. An address of 0.0.0.0
allows both localhost access and
IP or hostname access. Default is localhost
.
在你作为 运行 in vagrant 的情况下,你需要确保它绑定到 0.0.0.0
python /home/vagrant/code/google-cloud-sdk/platform/google_appengine/dev_appserver.py \
PATH_TO_app.yaml \
--host=0.0.0.0 --port=7080 --admin_port=7000 --datastore_path=~/BLAH.db
我 运行 在 Vagrant box 中连接本地开发服务器并尝试在 Chrome(主机)中打开它。但是它无法在主机中打开。使用 curl
on localhost:7000 在来宾机器 returns HTML 的内容。这是我的 Vagrant 文件
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.provision :shell, path: "setup_dev_env.sh"
config.vm.box_check_update = false
config.vm.network "forwarded_port", guest: 7080, host: 7080, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 7000, host: 7000, host_ip: "127.0.0.1"
config.vm.synced_folder "SOME_PATH", "/home/vagrant/code"
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.memory = "4096"
end
end
向运行服务器(来宾计算机)发出的命令:
python /home/vagrant/code/google-cloud-sdk/platform/google_appengine/dev_appserver.py PATH_TO_app.yaml --port=7080 --admin_port=7000 --datastore_path=~/BLAH.db
您需要在运行您的命令(https://cloud.google.com/appengine/docs/standard/python3/tools/local-devserver-command)
时添加以下内容--host=...
The host address to use for the server. You may need to set this to be able to access the development server from another computer on your network. An address of
0.0.0.0
allows both localhost access and IP or hostname access. Default islocalhost
.
在你作为 运行 in vagrant 的情况下,你需要确保它绑定到 0.0.0.0
python /home/vagrant/code/google-cloud-sdk/platform/google_appengine/dev_appserver.py \
PATH_TO_app.yaml \
--host=0.0.0.0 --port=7080 --admin_port=7000 --datastore_path=~/BLAH.db