当我在Virtualbox上运行Vagrant时,使用Gatsby时无法进行端口转发。
Gatsby默认在本地主机端口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