Chrome 无法使用 Gulp/BrowserSync 打开 localhost:3000 [英] Chrome can't open localhost:3000 with Gulp / BrowserSync

查看:18
本文介绍了Chrome 无法使用 Gulp/BrowserSync 打开 localhost:3000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,无论我尝试什么,谷歌浏览器似乎都无法显示 http://localhost:3000(或任何其他指定的端口号)在通过 Gulp 使用 BrowserSync 启动服务器时.

For some reason, no matter what I try, Google Chrome never seems to be able to display http://localhost:3000 (or any other specified port number for that matter) when starting up a server with BrowserSync through Gulp.

在 Firefox 中导航到相同的 URI,表明它可以工作并且 BrowserSync 已连接.

Navigating to the same URI in Firefox, shows that it works and that BrowserSync is connected.

gulp.task('browser-sync', function() {
    browserSync.init({
        server: {
            baseDir: './'
        },
        port: 8080
    });
});

我将上面的端口 8080 指定为 替代,但即使使用默认的 3000 在 Chrome 中也不起作用.Firefox 似乎都可以使用.

I'm specifying port 8080 above as an alternative, but even using the default 3000 does not work in Chrome. Firefox seems to be able to work with either.

我去过:chrome://net-internals/#dns 并清除了主机缓存,重新启动等.没有任何效果.

I've been to: chrome://net-internals/#dns and cleared the host cache, restarted, etc. Nothing works.

在 Chrome 中,我只收到消息:ERR_CONNECTION_REFUSED

In Chrome I simply get the message: ERR_CONNECTION_REFUSED

有什么想法吗?谢谢.

PS - 也适用于 Safari.

PS - Also works in Safari.

推荐答案

如果这对任何人有帮助,我就解决了这个问题.

I figured out the issue if this helps anybody.

通过 BrowserSync 提供的公共 IP 访问该站点有效,但我仍然需要 localhost:3000,因此我进一步调查了 Mac 上的 hosts 文件.

Accessing the site through the public IP that BrowserSync gives worked, but I still needed localhost:3000, so I investigated further into the hosts file on Mac.

默认情况下,这一行似乎是影响连接的行:

By default it seems this line was the one affecting the connection:

::1    localhost

您所要做的就是将这一行注释掉,一切都会好起来的:

All you have to do is comment this line out and all should be fine:

#::1    localhost

希望这对在 Mac 上使用 Gulp 和 BrowserSync 和 Chrome 有类似问题的人有所帮助.

Hope this helps someone with a similar issue using Gulp and BrowserSync with Chrome on a Mac.

这篇关于Chrome 无法使用 Gulp/BrowserSync 打开 localhost:3000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆