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

部署在AWS LightSail上的Express API无响应问题排查求助

Troubleshooting Unresponsive Express Service on AWS Lightsail Ubuntu 20.04

Hey there, let’s work through this unresponsive Express server issue on your Lightsail Ubuntu instance. I’ve dealt with similar head-scratchers before, so let’s break down the most common fixes step by step.

1. Confirm the Server is Running on the Instance

First, log into your Lightsail instance via SSH and check if your Node.js process is active:

  • Run ps aux | grep node to see if your Express app is running. If it’s missing, restart it (make sure you’re in the app directory and run node your-app-file.js—pro tip: use pm2 to keep it running in the background so it doesn’t die when you close the SSH session).
  • Check startup logs: if you’re running the server directly, you should see the "server started at port 3000" message in your terminal. If using pm2, run pm2 logs to verify the server booted successfully.

2. Open Port 3000 in Ubuntu’s UFW Firewall

Ubuntu 20.04 uses ufw by default, and it might be blocking external traffic to port 3000:

  • Run sudo ufw status to view current rules. If you don’t see 3000 listed as allowed, add it with sudo ufw allow 3000/tcp.
  • Recheck with sudo ufw status—you should see ALLOW 3000/tcp under the "To Action From" section.

3. Update Lightsail’s Network Firewall Rules

AWS Lightsail has a separate network-level firewall that overrides OS-level rules:

  • Head to your Lightsail dashboard, select your instance, then click the Networking tab.
  • Under Firewall rules, check for an inbound rule allowing TCP traffic on port 3000. If there’s none, add a new rule: set "Application" to "Custom", "Protocol" to "TCP", "Port range" to "3000", and "Source" to "0.0.0.0/0" (or restrict to your specific IP if you prefer tighter security).

4. Test Connectivity Locally on the Instance

To rule out app-level issues, test the endpoint directly from the server:

  • Run curl http://localhost:3000 in your SSH terminal. If you get the {"msg":"worked"} response and see the "hit hit hit" log, the app is working locally—your problem is with external network access.
  • If this fails, double-check that Node.js is installed correctly (run node -v to confirm) and that your simplified code has no typos (it looks solid, but it never hurts to double-check).

5. Ensure the Server Listens on All Interfaces

Sometimes apps bind only to localhost (127.0.0.1), making them unreachable from outside the instance. Update your app.listen line to explicitly bind to all interfaces:

app.listen(3000, '0.0.0.0', ()=>{
 console.log("server started at port 3000, listening on all interfaces");
})

This ensures the server accepts connections from any IP address, not just the local machine.

6. Check for Port Conflicts

Make sure no other process is using port 3000:

  • Run sudo lsof -i :3000 to list processes using the port. If you see another process, kill it with sudo kill -9 <PID> (replace <PID> with the process ID) or switch your Express app to a different port.

After working through these steps, your server should start responding. Let me know if any of these checks reveal the root cause!

内容的提问来源于stack exchange,提问作者Ahmad Kashif

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 10:23:10