简体   繁体   中英

How to enable access to a web service hosted on GCP VM instance

I built a web app, that runs and listens on port 5000 using .netcore (default app in VS). I created a VM instance on GCP, and allowed http and https traffic in the configuration. I ran the app, and used the exteral ip(which I succeeded to ping) to access it from the browser: http://:5000

But I got no response, this should have opened the site. I added a firewall rule to allow traffic but still didn't help: 在此处输入图片说明 I'm sure many people encountered this, any help?

The firewall is dropping your traffic. You should open port 5000, not http(port 80) or https(port 443).

I have the same opinion as @Iñigo, it could be the firewall.

You can create the rule with the following command:

gcloud compute --project=my-project firewall-rules create rule-for-netcore --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:5000 --source-ranges=0.0.0.0/0

The output should be something like:

Creating firewall...⠹Created [https://www.googleapis.com/compute/v1/projects/my-project...l/firewalls/rule-for-netcore].
Creating firewall...done.
NAME              NETWORK  DIRECTION  PRIORITY  ALLOW     DENY  DISABLED
rule-for-netcore  default  INGRESS    1000      tcp:5000        False

Edit 1

Also you need to open the port in your windows firewall:

  1. From the Start menu, click Control Panel , click System and Security , and then click Windows Firewall . Control Panel is not configured for 'Category' view, you only need to select Windows Firewall .
  2. Click Advanced Settings .
  3. Click Inbound Rules .
  4. Click New Rule in the Actions window.

在此处输入图片说明

  1. Click Rule Type of Port .
  2. Click Next.
  3. On the Protocol and Ports page click TCP.
  4. Select Specific Local Ports and type a value something like 5000-5010 (this is only an example you need to add the ports needed)
  5. Click Next.
  6. On the Action page click Allow the connection .
  7. Click Next.
  8. On the Profile page click the appropriate options for your environment.
  9. Click Next.
  10. On the Name page enter a name of like “Open port for test”
  11. Click Finish.
  12. Restart the Instance.

At the end you would see the rule like this: 在此处输入图片说明

You can consult the following link for more information.

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