我一直在尝试使用 gulp 使 browsersync 在 vagrant 中工作。我可以连接到 browsersync 的 UI,但我永远无法连接到我的开发站点。如果尝试使用地址 http://localhost:3000
进行连接,我不断收到以下错误:
Cannot GET /
这是我对 vagrant 的配置:
# IP Address to access the server 10.0.0.3
config.vm.network "private_network", ip: "10.0.0.3"
config.vm.network "forwarded_port", guest: 3000, host: 3000, auto_correct: true
config.vm.network "forwarded_port", guest: 3001, host: 3001, auto_correct: true
# Sync the server timezone to the host machine
config.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/Asia/Manila /etc/localtime", run: "always"
# Sync File
config.vm.synced_folder "./", "/var/www/html", mount_options: ["dmode=777", "fmode=666"]
连接 SQL 时的配置
以下是我对 Gulp 的配置:
browserSync.init(["./assets/css/*.css"],{
server: {
proxy: "http://10.0.0.3/globe-gui/",
open: false,
port: "2222",
injectChanges: true,
}
});
我尝试在网上搜索解决方案,但似乎无法得到答案。
最佳答案
浏览器同步未使用 the correct options 初始化.
browserSync.init({
files: ["./assets/css/*.css"],
open: false,
port: "2222",
injectChanges: true,
proxy: "http://10.0.0.3/globe-gui/",
});
您的
Vagrantfile
将客户机(框)配置为可通过 IP 地址访问 10.0.0.3
.通过 IP 地址(
10.0.0.3
)从主机连接到盒子中运行的服务。将 SSH 主机设置为
10.0.0.3
用于在端口 2222
上运行的数据库服务从主机连接到盒子时在盒子中,但设置localhost
在盒子内部连接时。我认为
BrowserSync
是在盒子里面开始的。将代理配置为具有值:
proxy: "http://localhost/globe-gui/",
连接到
BrowserSync
通过 box (http://10.0.0.3:3000
) 的私有(private) IP 地址从在主机中运行的浏览器。
关于gulp - 尝试使用 gulp 使 browsersync 在 vagrant 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60445191/