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

CentOS7部署Node.js Express服务出现无法访问问题求助

Troubleshooting Your Node.js Service on CentOS 7

Hey there! Let's work through this issue step by step—since you're new to running Node.js on CentOS 7, we'll break down each possible cause and fix:

1. Verify Your Node Service is Actually Running

First, make sure your Node app is up and listening. Run this command in your server's terminal:

ps aux | grep node

You should see your Node process listed here. If not, start your app directly with node your-file-name.js and check for any error messages in the terminal—don't forget to run npm install express first if you haven't installed the dependency yet!

2. Check if the Port is Bound to All Interfaces

By default, some Node apps only listen on the localhost (127.0.0.1) interface, which means it's only accessible from the server itself, not externally. To confirm this, run:

ss -tulpn | grep 3000

Look for the Local Address column—if it shows 127.0.0.1:3000 instead of 0.0.0.0:3000, you need to update your listen call to bind to all interfaces:

app.listen(app.get('port'), '0.0.0.0', () => {
  console.log('server on port ', app.get('port'));
});

Restart your Node app after making this change.

3. Fix Firewall Rules (CentOS 7 Uses Firewalld by Default)

You ran iptables commands, but CentOS 7 typically uses firewalld as the default firewall service, so your iptables rules might not be taking effect. Try these commands instead:

# Add the port permanently
firewall-cmd --add-port=3000/tcp --permanent
# Reload the firewall to apply changes
firewall-cmd --reload

If you are using iptables directly, make sure to save your rules and restart the service:

service iptables save
service iptables restart

4. Check Your Cloud Server's Security Group (If Applicable)

If you're using a cloud server (AWS, Alibaba Cloud, Tencent Cloud, etc.), the provider's security group acts as an additional firewall layer. You'll need to log into your cloud console, find your server's security group, and add an inbound rule allowing TCP traffic on port 3000 from your IP (or all IPs, if you want public access). This is a super common gotcha for new users!

5. Test Local Access First

To narrow down the issue, test accessing the service from the server itself:

curl http://localhost:3000

If this works, the problem is definitely with external network access (firewall/security group). If it doesn't work, your app isn't running correctly or isn't listening on the right port.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 03:13:30