简体   繁体   中英

can't access google cloud compute engine VM through external IP (nodejs)

For testing purposes, I've created a Google Cloud Compute Engine VM (Debian 9).

I installed nodejs and created a small script. When navigating to the external ip address through my browser, nothing happens.

const express = require('express')()

express.get('/', (req, res) => {
    console.log('browser access')
}

express.listen(8000, () => console.log('server is running'))

When navigating to http://[EXTERNAL_IP_ADDRESS]:8000 , nothing happens.

  • I have SSH access through the external IP, it works

  • I can ping to the external IP address, this works too

  • When doing 'node app.js' through the terminal (SSH access), I see 'server is running'

  • I have set a firewall rule to accept all incoming trafic on tcp=8000 (IP range 0.0.0.0/0)

  • I have the firewall rules default-allow-http (tcp: 80) and default-allow-https (tcp: 443)

  • I have a static IP address

Is there something I'm missing?

Edit:

  • When I visit the server (with :8000) through my browser, the page keeps loading. But the message 'browser access' is not send to the console. After let's say 30 seconds, I get an ERR_CONNECTION_TIME_OUT in the browser.

  • Express version is 4.17.1. I also changed 'express' to 'app'.

  • When I open a terminal window and do 'curl EXTERNAL_IP_ADDRESS:8000', nothing happens. It seems like it keeps loading.

  • I changed listen(8000) to listen(8000, '0.0.0.0'). No differences are observed.

Problem solved:

I got it working. I installed ufw on the VM and opened up port 8000. That was the solution for me.

Solution:

Not only did I need to add a firewall rule to my VPC (0.0.0./0 tcp:8000, incoming), I also needed to open the port 8000 on my VM itself. I installed ufw and opened port 8000. It's working now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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