Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Your website on a Google Compute Engine VM times out on port 80

ErrorConnection timeout when opening http://EXTERNAL_IP in the browser

Short answer

A timeout, as opposed to a refusal, usually means a firewall dropped the packets. Google Cloud blocks all incoming traffic unless an ingress rule allows it, and the default network has no rule for port 80. Add an allow rule for tcp:80 and tcp:443, make sure its target tag matches the VM, and confirm nginx listens on all addresses.

  • Applies to Google Cloud VPC, nginx 1.26, Debian 12 / Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Test from the VM itself first. If curl works on the VM but fails from outside, the firewall is the cause; if it fails on the VM too, nginx is.

    curl -I http://127.0.0.1
    sudo ss -ltnp | grep -E ':80|:443'
  2. 2Match what you see, then jump to its fix

    1. 1curl works on the VM, times out from your computerNo ingress firewall rule allows tcp:80Fix
    2. 2A rule for tcp:80 is listed with target tags, and the VM still times outThe rule exists but its target tag is not on the VMFix
    3. 3ss shows 127.0.0.1:80 instead of 0.0.0.0:80 or *:80nginx listens on the loopback address onlyFix

What does the error look like?

  • Connection timeout when opening http://EXTERNAL_IP in the browser
  • The site works with curl on the VM but not from outside

Cause 1 of 3

No ingress firewall rule allows tcp:80

1Check

Without a matching rule the implied deny ingress blocks the traffic, including from the internet. The default network only starts with rules for internal traffic, SSH, RDP and ICMP, not HTTP.

gcloud compute firewall-rules list

2Fix

Create an allow rule for ports 80 and 443. Narrow the source range if the site is not public.

gcloud compute firewall-rules create allow-web-http-https \
    --network=default \
    --action=ALLOW \
    --direction=INGRESS \
    --rules=tcp:80,tcp:443 \
    --source-ranges=0.0.0.0/0 \
    --target-tags=web

3Verify

Request the VM's external IP from your own computer.

curl -I http://EXTERNAL_IP

Confirmed by docs.cloud.google.com

Did this fix it?

Cause 2 of 3

The rule exists but its target tag is not on the VM

1Check

A rule with a target tag applies only to instances that carry at least one matching tag. Compare the tags on the rule with those on the VM.

gcloud compute firewall-rules describe allow-web-http-https
gcloud compute instances describe my-vm --zone=us-central1-a

2Fix

Add the matching network tag to the VM in the console (VM details, Edit, Network tags), or recreate the rule without --target-tags so it applies to every instance in the network.

# no target tag: applies to all instances in the network
gcloud compute firewall-rules create allow-web-all \
    --network=default --action=ALLOW --direction=INGRESS \
    --rules=tcp:80,tcp:443 --source-ranges=0.0.0.0/0

3Verify

Request the external IP again from outside.

curl -I http://EXTERNAL_IP

Confirmed by docs.cloud.google.com

Did this fix it?

Cause 3 of 3

nginx listens on the loopback address only

1Check

A listen directive with an address binds only to that address. listen 127.0.0.1:80 accepts local connections and nothing else.

grep -rn "listen" /etc/nginx/sites-enabled/ /etc/nginx/conf.d/
sudo ss -ltnp | grep nginx

2Fix

Use a port-only listen, which accepts on all addresses, then reload.

server {
    listen 80;
    listen [::]:80;
}

3Verify

Test the config, reload, and request from outside.

sudo nginx -t && sudo nginx -s reload
curl -I http://EXTERNAL_IP

Confirmed by nginx.org

Did this fix it?

How do I stop it coming back?

  • Create the web firewall rule as part of the VM setup, not afterwards.
  • Use one tag name for web servers and write it down next to the rule.
  • Always test from the VM first, then from outside, to split firewall from server.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

nginx gives up waiting for the app and returns 504

upstream timed out (110: Connection timed out) while reading response header from upstream

nginx returns 504 when the app behind it takes the request but sends nothing back within proxy_read_timeout (60 seconds by default), or when the connection cannot be opened in time.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.