【发布时间】:2018-10-14 07:46:19
【问题描述】:
当使用在 Vagrant(通过 Virtualbox)上运行的 Gatsby 时,我无法让端口转发工作。
Gatsby 默认在 localhost 端口 8000 上运行。
我的 Vagrantfile 似乎使用以下方式转发了正确的端口:
config.vm.network "forwarded_port", guest: 8000, host: 8000
当我在 Vagrant 机器上使用 yarn develop 启动 Gatsby 时,访客机器上一切正常,应用程序正在 localhost:8000 上运行
info bootstrap finished - 7.354 s
DONE Compiled successfully in 9091ms
You can now view foo-bar-org in the browser.
http://localhost:8000/
我可以在访客框上运行curl http://localhost:8000 来验证它确实在本地提供内容。
当我进入浏览器并尝试访问 http://localhost:8000 时返回主机框,它显示“Localhost 拒绝连接”。
在访客框上运行 netstat -tulnp | grep 8000 我得到以下信息:
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1909/node
在主机箱上运行同样的程序,我得到了这个输出:
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 13827/VBoxHeadless
【问题讨论】:
标签: javascript reactjs vagrant virtualbox gatsby