为什么 Vagrant 不绑定我的 Django/Wagtail 服务器?
Why isn't Vagrant binding my Django/Wagtail server?
我按照教程 here 进行了调用 djrun
,但发现 http://localhost:8000
没有任何反应。
除了确保正确绑定 Django 的运行服务器 ./manage.py runserver 0.0.0.0:8000
,您还需要检查 Vagrant 是否正在为主机转发端口。这可以看作是来自 vagrant up
命令的 STDOUT 的一部分:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'wagtail-base-v0.3'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: gilles_default_1431922616155_88032
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 8000 => 8111 (adapter 1) # <== This is the relevant line.
default: 22 => 2222 (adapter 1)
因此,服务器位于 http://localhost:8111/
编辑
根据下面的评论,您还可以通过 Vagrant 配置文件设置此值。配置密钥称为 config.vm.forwarded_port
。下面是启动示例文件(默认情况下由 Wagtail 提供):
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# Base box to build off, and download URL for when it doesn't exist on the user's system already
config.vm.box = "wagtail-base-v0.3"
config.vm.box_url = "http://downloads.torchbox.com/wagtail-base-v0.3.box"
# Forward a port from the guest to the host, which allows for outside
# computers to access the VM, whereas host only networking does not.
config.vm.forward_port 8000, 8111 # <-- This is the relevant line.
我按照教程 here 进行了调用 djrun
,但发现 http://localhost:8000
没有任何反应。
除了确保正确绑定 Django 的运行服务器 ./manage.py runserver 0.0.0.0:8000
,您还需要检查 Vagrant 是否正在为主机转发端口。这可以看作是来自 vagrant up
命令的 STDOUT 的一部分:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'wagtail-base-v0.3'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: gilles_default_1431922616155_88032
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 8000 => 8111 (adapter 1) # <== This is the relevant line.
default: 22 => 2222 (adapter 1)
因此,服务器位于 http://localhost:8111/
编辑
根据下面的评论,您还可以通过 Vagrant 配置文件设置此值。配置密钥称为 config.vm.forwarded_port
。下面是启动示例文件(默认情况下由 Wagtail 提供):
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# Base box to build off, and download URL for when it doesn't exist on the user's system already
config.vm.box = "wagtail-base-v0.3"
config.vm.box_url = "http://downloads.torchbox.com/wagtail-base-v0.3.box"
# Forward a port from the guest to the host, which allows for outside
# computers to access the VM, whereas host only networking does not.
config.vm.forward_port 8000, 8111 # <-- This is the relevant line.