How Do You Create a GCP VM to Be a Web Server?

Problem scenario
You have a GCP server. You can run curl commands to its URL via localhost. But with a URL constructed with the server's external IP address the curl command times out. You cannot reach the URL from your workstation. How do you get the GCP server to present the web service to other machines?

Solution
Modify the firewall rule by following these steps below.
1. Go to the VM's details (go to the hamburger icon in the upper righthand corner, then go to VM Instances and click on the VM).
2. Look for the "Network tags". You will find something like "http-server" or "https-server". Make a mental note of one of them.
3. Go to the hamburger icon in the upper righthand corner, go to VPC Network -> Firewall Rules.
4. Click "CREATE FIREWALL RULE".
5. Enter a relevant port in "Protocols and ports" (e.g., 8080 or just 80) and a relevant IP Range in "Source filters" (e.g., 0.0.0.0/0 if it is not sensitive).
6. Click "Save".

Leave a comment

Your email address will not be published. Required fields are marked *