jasonC
jasonC

Reputation: 347

How to access Google Cloud Engine instance's IP address via browser

I installed a MEAN stack on Google Cloud Engine (GCE) via this link.

So the engine created my instance successfully and it looks like this: instance's info on GCE

I created a new firewall rule to accept any incoming requests (actually do I need to do this? default-allow-http has the same rule right?): enter image description here

But when I try to access the IP using Chrome, I get an error. The error persists even when I change the browser e.g. IE or Firefox:

enter image description here

I have confirmed that I can ping the address: enter image description here

I even tried to assign a domain name to the instance but it still does not work: enter image description here

May I know what I am doing wrongly?

Would appreciate any advice! Thanks in advance!

Upvotes: 14

Views: 15634

Answers (5)

ThE_DaTa_GuY
ThE_DaTa_GuY

Reputation: 1

To access Google VM Instances through http follow below steps:

  1. Create firewall rule with TCP protocol 2)Enter/Edit the firewall rule with port no. in my case it was 9870 for Namenode for Hadoop 3.2.2
  2. Access in any browser type: http://(host-ip-add):9870

NOTE: Edit the port no. as per you requirements

firewall setting

Upvotes: 0

Braian Coronel
Braian Coronel

Reputation: 22867

I had the same problem after installing the JIRA Core app, and I was able to solve it with the following steps. I honestly did not install MEAN stack but most of the steps to solve this error must be the same (except for port verification and service execution).

  1. The first thing is to detect the port used by MEAN stack app in the official documentation and in some configuration file generated by the installation of the app. According to information in the comments the app uses the port 3000

  2. You go to the GCP console to add a VPC Network firewall rule.

    a. You choose the project where you have the instance.

    b. Select VPC Network -> Firewall Rules -> Create

    c. Name: mean-stack

    d. Intervals of IPs: 0.0.0.0/0

    e. Protocols/ports: tcp:3000; udp:3000

  3. List the ports that the VM is listening to or the firewall enables from the Cloud Shell:

    $ netstat -an | grep "LISTEN "

  4. You have to open the port for MEAN stack that blocks the firewall. If the port is listening, this step is not necessary:

    $ sudo apt-get install ufw

    $ sudo ufw enable

    $ sudo ufw allow ssh //so as not to be disconnected from the instance by ssh

    $ sudo ufw allow 3000

    If the app uses more control ports, you must also enable them

  5. You should check that the app is on and running with some command (For example: sudo /opt/bitnami/ctlscript.sh start apache)

  6. You should test if you can access the MEAN stack app locally through the URL. The following command does NOT have to give me connection refused.

    $ sudo wget http://localhost:3000

    Do not enter the URL generated by wget, as it must be done with an external ip.

  7. Finally, after creating a firewall rule for the project of the instance and enabling the port that blocks the firewall you can access from any client through the browser.

    http://< external-ip-vm >:< port >

    http://104.154.39.199:3000

I hope I can help you at some point. GL

Upvotes: 5

Nicolas
Nicolas

Reputation: 69

MEAN stack app is running with Express on port 3000 (default address) only on localhost address for security reason. To promote application to be visible on internet (on port 80), just create a proxy reverse clause on apache (or nginx, or...).

sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf

add this statement like this : ProxyPass http://localhost:3000 ProxyPassReverse http://localhost:3000

sudo /opt/bitnami/ctlscript.sh restart apache

if app is lauched on your instance you can open it using http://address_of_VMInstance/yourapp

Upvotes: 1

Kevin
Kevin

Reputation: 1130

More explicitly - The firewall's job is simply to intercept disallowed incoming connections and silently drop them.

In this case, you: (a) see ping responses from the VM's public IP address, indicating that ICMP is not blocked by the firewall. (b) see a TCP RST packet sent by the VM in response to the TCP SYN packet your browser sent as it attempted to connect to a TCP server on the VM. This indicates that packets addressed to TCP port 80 are also passed by the firewall, as expected.

What's missing here is a server application on your VM that listens to connections on port 80, receives HTTP requests and responds. You might try running, say, Apache (or Nginx, which is even simpler to set up).

In answer to your other question - you don't need the second tcp:80 firewall rule - but if you want the default http rule to allow packets to your VM, you will need to a tag to your VM labelled "http-server".

Upvotes: 0

Subbaiah Venkata
Subbaiah Venkata

Reputation: 49

The error is CONNECTION_RESET. My guess is MEAN stack is not listening on port 80.

Upvotes: -1

Related Questions