Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 276
jasonC Avatar asked Apr 21 '16 02:04

jasonC


People also ask

How to see IP address on Google Cloud?

Viewing IP addressesIn the Google Cloud console, go to the VM instances page. If the VM instance has an external IP address, it appears under the External IP column. If a VM does not have an external IP address, you can assign one.

How do I access GCP VM from browser?

In the Google Cloud console, go to the VM instances page. In the list of VMs, click the arrow_drop_down drop-down next to the SSH button of the VM that you want to connect to. Click Open in browser window using provided private SSH key. The SSH-in-browser window opens.

How to connect to gcp VM without external IP?

To connect to an instance without an external IP address, use the gcloud compute ssh command with the --internal-ip flag. In the Google Cloud console, go to the VM Instances page and find the internal IP address for the instance that you want to connect to. Connect to the instance.

How do I access Google Cloud SSH?

Log in to the Google Cloud Console and select your project. Navigate to the “Compute Engine -> VM Instances” page and select the server you wish to connect to. Click the “Edit” link in the top control bar. On the resulting page, copy and paste your public SSH key into the “SSH Keys” field.


2 Answers

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

like image 127
Braian Coronel Avatar answered Oct 20 '22 22:10

Braian Coronel


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

like image 39
Nicolas Avatar answered Oct 20 '22 23:10

Nicolas