Your website on a Google Compute Engine VM times out on port 80
Connection timeout when opening http://EXTERNAL_IP in the browserShort 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.
Fix it fast
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'2Match what you see, then jump to its fix
- 1
curl works on the VM, times out from your computerNo ingress firewall rule allows tcp:80Fix - 2
A 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
ss shows 127.0.0.1:80 instead of 0.0.0.0:80 or *:80nginx listens on the loopback address onlyFix
- 1
What does the error look like?
Connection timeout when opening http://EXTERNAL_IP in the browserThe 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 list2Fix
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=web3Verify
Request the VM's external IP from your own computer.
curl -I http://EXTERNAL_IPConfirmed by docs.cloud.google.com
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-a2Fix
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/03Verify
Request the external IP again from outside.
curl -I http://EXTERNAL_IPConfirmed by docs.cloud.google.com
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 nginx2Fix
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_IPConfirmed by nginx.org
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 fixServers
A Let's Encrypt certificate did not renew with Certbot
Type: connection ... Timeout during connect (likely firewall problem)
Run sudo certbot renew --dry-run and read the Type and Detail lines.
6 causes, each with a fixServers
curl cannot connect to port 80 or 443 on a server running nginx
CURLE_COULDNT_CONNECT (7): Failed to connect() to host or proxy
Exit code 7 means the TCP connection itself failed, before any HTTP happened.
3 causes, each with a fixServers
Django returns a 500 behind Gunicorn and the traceback is nowhere
The traceback shows locally with runserver but not under Gunicorn
With DEBUG set to False, Django's default logging does not print errors to the console.
2 causes, each with a fixServers
Gunicorn rejects a request with "Error parsing headers: limit request headers fields size"
Error parsing headers: 'limit request headers fields'
Gunicorn caps the size of one header field at 8190 bytes and the number of headers at 100 by default.
2 causes, each with a fixServers
HAProxy answers 503 "No server is available to handle this request"
No server is available to handle this request.
HAProxy sends 503 when it has no server to give a request to.
4 causes, each with a fix