简体   繁体   English

Google Cloud上的虚拟Ubuntu VM无法通过Node.js,外部IP连接

[英]Virtual Ubuntu VM on Google Cloud can't connect via nodejs, external ip

var express = require('express');
var bodyParser = require('body-parser');
var path = require('path');

var app = express();

app.listen(3000, function(){
        console.log('Server up on Port 3000');
});

I did search and try other solutions here but I still can't figure it out 我确实在这里搜索并尝试了其他解决方案,但仍然无法弄清楚

I have ubuntu on a google cloud compute engine (VM) and i'm trying to access it from the internet on my laptop. 我在Google云计算引擎(VM)上安装了ubuntu,我正尝试从笔记本电脑上的互联网访问它。 I'm using nodejs/ npm/ express. 我正在使用nodejs / npm / express。

The above is my index.js file (very basic) and when I start that using the following on the VM 上面是我的index.js文件(非常基本),当我在VM上使用以下代码启动该文件时

nodejs index.js

35.188.226.109 is the external ip for the VM 35.188.226.109是VM的外部IP

When navigating in chrome to http://35.188.226.109:3000/ it says the site can't be reached. 在Chrome浏览器中浏览到http://35.188.226.109:3000/时 ,表示无法访问该网站。

What am I missing? 我想念什么?

When you launch a VM in the GCP, it's connected with a default network. 当您在GCP中启动VM时,它与默认网络连接。 That default network is in the most secure settings and will have firewall based port blocking for all the port except SSH and few others. 该默认网络处于最安全的设置中,除SSH和其他少数端口外,所有端口均具有基于防火墙的端口阻止功能。

In order to allow external applications to communicate with your VM you have to enable access to your machine by enabling the port from the firewall. 为了允许外部应用程序与您的VM通信,您必须通过启用来自防火墙的端口来启用对计算机的访问。

Firewall settings can be found here . 防火墙设置可以在这里找到。

In your case, add a new firewall rule to allow port 3000 from all the IPs. 在您的情况下,添加新的防火墙规则以允许来自所有IP的端口3000。 Remember that this is not the best practice. 请记住,这不是最佳实践。 Use port forwarding, proxies etc. 使用端口转发,代理等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM