Access localhost on Google Cloud instance using External IP

Viewed 12311

There are many similar questions to this on SO, but none of the solutions I saw really solved my issue completely. I'm doing test runs for a website framework hosted on the Google Cloud Platform.

By default, the website is hosted on http://localhost:2800 And I know the external IP of the instance I'm running it on. How can I access the hosted website through a browser on my local machine? Do I use virtual hosts / port forwarding etc.?

4 Answers

go to your VPC firewall

https://console.cloud.google.com/networking/firewalls

and create a firewall rule to allow traffic on your desired tcp port

Create a Firewall Rule for SQL Server Configure a firewall rule to allow traffic on port 1433 so other clients can connect to the newly created SQL Server instance over the public internet:

In the Developers Console main menu, go to the Firewall rules section.

OPEN THE FIREWALL RULES

Click the Add firewall rule button.

Name the new firewall rule allow-tcp-1433.

Set Source Filter to IP Ranges.

For Source IP Ranges enter 0.0.0.0/0. This value allows access by all IP addresses.

Warning: This configuration leaves your SQL Server instance open to traffic from everyone, everywhere. It is used only for demonstration purposes. In production environments, restrict access to only those IP addresses that need access. For Allowed protocols and ports enter tcp:1433. Click the Create button to create the firewall rule.

  1. Set firewall rules for you google cloud project with following properties:
    Target: all instances
    Direction: ingress
    Source IP ranges: 0.0.0.0/0
    Ports and protocols: allow all

  2. Then Depending on your framework, set allowed_host to externalIP or "*" .
    For example - In Django, in settings.py set ALLOWED_HOSTS = ["*"]

  3. Now run server on specific 0.0.0.0:[your_port]
    For example in django - Python manage.py runserver 0.0.0.0:8000

  4. After this note down you instance external IP address and then in your browser :-
    goto [external-IP:[your_port]]

you have to go VPC network, then add firewall to allow your port. then don't forget to select [All intances in the network] (see pic). because, by default its value is [Spesified by tags].

and you can access that instance to its External IP

enter image description here

Try your [externalip]:[port] This worked for me in Amazom ec2. example: 31.181.171.141:2800

Related