当使用在 Vagrant(通过 Virtualbox)上运行的Gatsby时,我无法使端口转发工作。
默认情况下,Gatsby 在本地主机端口 8000 上运行。
我的 Vagrantfile 似乎使用以下方法转发正确的端口:
config.vm.network "forwarded_port", guest: 8000, host: 8000
Run Code Online (Sandbox Code Playgroud)
当我在 Vagrant box 上使用 启动 Gatsby 时yarn develop,guest box 上一切正常,应用程序在 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/
Run Code Online (Sandbox Code Playgroud)
我可以curl http://localhost:8000在来宾盒上运行以验证它确实在本地提供内容。
当我进入浏览器并尝试访问http://localhost:8000时,返回主机框,它显示“本地主机拒绝连接”。
netstat -tulnp | grep 8000在来宾盒上运行我得到以下信息:
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1909/node
Run Code Online (Sandbox Code Playgroud)
在主机箱上运行相同的我得到这个输出:
tcp 0 0 0.0.0.0:8000 0.0.0.0:* …Run Code Online (Sandbox Code Playgroud)