使用 "npm start" 时,什么会阻止我的 html 页面在计算引擎虚拟机中显示
what would be stopping my html page from displaying in compute-engine vm upon using "npm start"
我是新手,希望我的错误有一个简单的答案。
我已经在计算引擎虚拟机中安装了 node.js 和 npm。我在虚拟机上使用 ssh 来访问我的文件。我创建了一个基本的 html 页面(我正在学习这部分课程)。我现在要通过命令 npm start 为该页面提供服务。当我启动它时,一切似乎都正常,但是当我单击外部 ip link 查看 html 页面时,它只是超时。我试过打开防火墙,但可能打开的防火墙不正确。我将不胜感激关于下一步尝试解决此问题的一些建议。谢谢
这是我看到的:
> gitstore@1.0.0 start /home/barklera/gitstore
> npm run lite
> gitstore@1.0.0 lite /home/barklera/gitstore
> lite-server
Did not detect a `bs-config.json` or `bs-config.js` override file. Using lite-server defaults...
** browser-sync config **
{
injectChanges: false,
files: [ './**/*.{html,htm,css,js}' ],
watchOptions: { ignored: 'node_modules' },
server: {
baseDir: './',
middleware: [ [Function (anonymous)], [Function (anonymous)] ]
}
}
[Browsersync] Access URLs:
-----------------------------------
Local: http://localhost:3004
External: http://<my ip>:3004
-----------------------------------
UI: http://localhost:3005
UI External: http://localhost:3005
-----------------------------------
[Browsersync] Serving files from: ./
[Browsersync] Watching files...
您必须创建防火墙规则以允许端口 3004 和 3005 上的入口流量(至少我在代码片段中看到了它们)。 By default they are blocked.
您可以使用 console ui 或 gcloud
命令来做到这一点:
gcloud compute --project=proj_name firewall-rules create myrule1 --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:3004,tcp:3005 --source-ranges=0.0.0.0/0 --target-tags=tag1
此外,要使此规则生效,您必须 assign "tag1" network tag 到您的实例。
此外 - 确保 VM 中的内部防火墙不会阻止该流量 - 它不应该但最好仔细检查一下:
netstat -tulpn | grep LISTEN
你会得到类似的东西:
wbogacz_google_com@ssh3-osl-enabled:~/.ssh$ netstat -tulpn | grep LISTEN
(No info could be read for "-p": geteuid()=1762585940 but you should be root.)
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:24224 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:514 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
您可以清楚地看到机器正在侦听的端口 - 那里应该有 3004/3005 端口。
我是新手,希望我的错误有一个简单的答案。 我已经在计算引擎虚拟机中安装了 node.js 和 npm。我在虚拟机上使用 ssh 来访问我的文件。我创建了一个基本的 html 页面(我正在学习这部分课程)。我现在要通过命令 npm start 为该页面提供服务。当我启动它时,一切似乎都正常,但是当我单击外部 ip link 查看 html 页面时,它只是超时。我试过打开防火墙,但可能打开的防火墙不正确。我将不胜感激关于下一步尝试解决此问题的一些建议。谢谢
这是我看到的:
> gitstore@1.0.0 start /home/barklera/gitstore
> npm run lite
> gitstore@1.0.0 lite /home/barklera/gitstore
> lite-server
Did not detect a `bs-config.json` or `bs-config.js` override file. Using lite-server defaults...
** browser-sync config **
{
injectChanges: false,
files: [ './**/*.{html,htm,css,js}' ],
watchOptions: { ignored: 'node_modules' },
server: {
baseDir: './',
middleware: [ [Function (anonymous)], [Function (anonymous)] ]
}
}
[Browsersync] Access URLs:
-----------------------------------
Local: http://localhost:3004
External: http://<my ip>:3004
-----------------------------------
UI: http://localhost:3005
UI External: http://localhost:3005
-----------------------------------
[Browsersync] Serving files from: ./
[Browsersync] Watching files...
您必须创建防火墙规则以允许端口 3004 和 3005 上的入口流量(至少我在代码片段中看到了它们)。 By default they are blocked.
您可以使用 console ui 或 gcloud
命令来做到这一点:
gcloud compute --project=proj_name firewall-rules create myrule1 --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:3004,tcp:3005 --source-ranges=0.0.0.0/0 --target-tags=tag1
此外,要使此规则生效,您必须 assign "tag1" network tag 到您的实例。
此外 - 确保 VM 中的内部防火墙不会阻止该流量 - 它不应该但最好仔细检查一下:
netstat -tulpn | grep LISTEN
你会得到类似的东西:
wbogacz_google_com@ssh3-osl-enabled:~/.ssh$ netstat -tulpn | grep LISTEN
(No info could be read for "-p": geteuid()=1762585940 but you should be root.)
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:24224 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:514 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
您可以清楚地看到机器正在侦听的端口 - 那里应该有 3004/3005 端口。