Google Compute Engine虚拟机npm start后HTML页面无法显示排查
Hey there! Let's work through this timeout issue step by step—since you're new, I'll keep each check simple and actionable.
First, let's recap what we know from your logs:
[Browsersync] Access URLs:
Local: http://localhost:3004 External: http://<my ip>:3004
Even though Browsersync shows an external URL, the most common culprit here is lite-server binding only to localhost (127.0.0.1) instead of all network interfaces. Let's start there:
Step 1: Make sure lite-server listens on all interfaces
By default, lite-server might only accept connections from the VM itself. To fix this, update your package.json to force it to bind to 0.0.0.0 (all interfaces):
- Open your
package.jsonvia SSH:nano /home/barklera/gitstore/package.json - Find the
scriptssection and modify thelitecommand:"scripts": { "start": "npm run lite", "lite": "lite-server --host 0.0.0.0" } - Save and exit (Ctrl+O, Enter, Ctrl+X), then restart the server:
npm start - Verify the logs now show the external IP correctly and the server is listening on 0.0.0.0.
Step 2: Double-check GCE Firewall Rules
You mentioned you tried opening the firewall, but let's confirm it's configured correctly:
- Go to Google Cloud Console → Compute Engine → VM Instances
- Click on your VM instance, then scroll to the Firewall section
- Ensure you have a rule that allows incoming TCP traffic on port 3004:
- Rule name (e.g.,
allow-lite-server) - Targets: All instances in the network (or just your specific VM)
- Source IP ranges:
0.0.0.0/0(to allow all external traffic) - Protocols and ports:
tcp:3004
- Rule name (e.g.,
- If no such rule exists, create it and wait 1-2 minutes for it to take effect.
Step 3: Check the VM's Internal Firewall
Many GCE VMs (like Ubuntu) use ufw as a local firewall. Let's make sure it's not blocking port 3004:
- Check the current status:
sudo ufw status - If port 3004 isn't listed as allowed, add it:
sudo ufw allow 3004/tcp - Verify the rule was added with
sudo ufw statusagain.
Step 4: Confirm the Port is Listening
To make sure lite-server is actually bound to the right interface, run this command in your VM:
ss -tulpn | grep 3004
You should see output like this (note 0.0.0.0:3004 instead of 127.0.0.1:3004):
LISTEN 0 511 0.0.0.0:3004 0.0.0.0:* users:(("node",pid=1234,fd=12))
If it shows 127.0.0.1:3004, go back to Step 1—your server is still only listening locally.
Step 5: Test Local Access First
Before testing external access, confirm the server works from inside the VM:
curl http://localhost:3004
If you see your HTML content, the server is running correctly. If not, check for typos in your HTML or server configuration.
Once all these steps are done, try accessing http://<your-VM-external-IP>:3004 again—this should resolve the timeout!
内容的提问来源于stack exchange,提问作者bark lera

