gpt4 book ai didi

vagrant - 如何将vagrant和browsersync与本地域一起使用?

转载 作者:行者123 更新时间:2023-12-03 08:49:56 24 4
gpt4 key购买 nike

我使用 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,但不能访问我的网站。

我不确定应该在哪里运行它。我应该如何在浏览器中访问该网站。如果我需要转发虚拟机中的任何端口。

在网络上搜索会返回很多结果,但它们都是关于咕or声或吞咽声的,我都不使用它们。

编辑:我将端口转发添加到 Vagrant ,然后从vm中启动浏览器同步。现在一切都可以在 http://example.dev:3000http://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

最佳答案

这就是我的工作方式。

我将端口转发添加到 Vagrant ,然后从虚拟机内部启动浏览器同步。现在一切都可以在http://example.dev:3000http://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

关于vagrant - 如何将vagrant和browsersync与本地域一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29023331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com