You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Compute Engine虚拟机npm start后HTML页面无法显示排查

Troubleshooting External Access to Your lite-server on GCE

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):

  1. Open your package.json via SSH:
    nano /home/barklera/gitstore/package.json
    
  2. Find the scripts section and modify the lite command:
    "scripts": {
      "start": "npm run lite",
      "lite": "lite-server --host 0.0.0.0"
    }
    
  3. Save and exit (Ctrl+O, Enter, Ctrl+X), then restart the server:
    npm start
    
  4. 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
  • 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:

  1. Check the current status:
    sudo ufw status
    
  2. If port 3004 isn't listed as allowed, add it:
    sudo ufw allow 3004/tcp
    
  3. Verify the rule was added with sudo ufw status again.

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 13:52:42