我使用 vagrant 并且我已将其配置为更新我的 etc/host 文件,这是一个示例。
10.20.1.36 example.dev
然后我可以使用http://example.dev/访问 VM 的 apache 服务器
我想从命令行使用 browsersync,但我无法访问我的网站。我在我的 mac 主机和 vagrant VM 上安装了 browsersync。我已经使用以下命令在我的 mac 和 VM 上进行了尝试,但它在这两种环境中都不起作用。
browser-sync start --proxy "example.dev" --files "public/*.html,public/css/*.css,public/js/*.js"
这是我从 Mac 得到的
[BS] Proxying: http://example.dev
[BS] Access URLs:
-------------------------------------
Local: http://localhost:3000
External: http://192.168.0.10:3000
-------------------------------------
UI: http://localhost:3001
UI External: http://192.168.0.10:3001
-------------------------------------
[BS] Watching files...
这是虚拟机中发生的事情
[BS] Proxying: http://example.dev
[BS] Now you can access your site through the following addresses:
[BS] Local URL: http://localhost:3000
[BS] External URL: http://10.0.2.15:3000
[BS] Watching files...
当我在 mac 中运行它时,我可以在http://localhost:3001/访问 browsersync ui,但不能访问我的网站。
我不确定我应该在哪里运行它。我应该如何在浏览器中访问该网站。如果我需要转发 VM 中的任何端口。
在网上搜索会返回很多结果,但它们都是关于 grunt 或 gulp 的,我不使用它们中的任何一个。
编辑:我将端口转发添加到 vagrant,然后从 vm 中启动 browser-sync。现在一切正常http://example.dev:3000
和http://example.dev:3001
。
这是我添加到我的 Vagrantfile 中的内容:
config.vm.network :forwarded_port, guest: 3000, host: 3000, auto_correct: true
config.vm.network :forwarded_port, guest: 3001, host: 3001, auto_correct: true