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

服务器无响应问题排查请求(Nginx/Ubuntu/Redis/MongoDB/PM2环境)

Hey there, let's troubleshoot this issue step by step—since your app isn't receiving requests despite appearing to run, we'll start with the most likely culprits first.

1. Verify Your App Is Actually Listening on the Correct Port

First, let's confirm if your PM2-managed app is truly listening for connections:

  • Run pm2 list to check the app's status. Note the port it's supposed to use (if configured in your app or PM2 settings).
  • Use ss -tulpn | grep <your-app-port> to check if the port is actively being listened on. If this command returns nothing, your app might have crashed (even if PM2 shows it as "online") or isn't configured to listen on the right interface.
  • Test local connectivity directly: run curl localhost:<your-app-port> on the server. If this doesn't return a response, the issue lies with your app itself—not Nginx. Check your app's code or PM2 logs for startup errors.
2. Double-Check Nginx Configuration & Setup

You mentioned checking /etc/nginx/sites-available, but let's cover all bases:

  • Ensure your config file is linked to the sites-enabled directory: run ls -l /etc/nginx/sites-enabled/ to see if there's a symlink to your config. If not, create it with sudo ln -s /etc/nginx/sites-available/your-config-file /etc/nginx/sites-enabled/.
  • Confirm your reverse proxy points to the correct app port. Your config should look something like this (adjust the port to match your app):
    server {
        listen 80;
        server_name your-domain-or-ip;
    
        location / {
            proxy_pass http://localhost:3000; # Replace with your app's port
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
    
  • Validate Nginx config syntax: sudo nginx -t. Fix any errors reported, then restart Nginx with sudo systemctl restart nginx.
3. Check Firewall & Security Group Rules

Ubuntu uses UFW by default—let's make sure traffic can reach Nginx:

  • Run sudo ufw status to see if the firewall is active. If it is, ensure HTTP (port 80) and/or HTTPS (port 443) are allowed:
    • Allow HTTP: sudo ufw allow 80/tcp
    • Allow HTTPS: sudo ufw allow 443/tcp
  • Critical note: If your server is on a cloud provider (AWS, Azure, Alibaba Cloud, etc.), check their security group settings too. You need to explicitly allow inbound traffic on ports 80/443 here—this is a super common oversight!
4. Validate Network Reachability
  • Confirm you're using the correct public IP: run curl ifconfig.me on your server to get its public IP, then compare it to the [myipadddress] you're trying to access.
  • Use tcpdump to check if requests are even reaching the server: run sudo tcpdump -i any port 80 on the server, then try accessing the IP from your local machine. If you don't see any incoming packets, the issue is network-level (wrong IP, security block, etc.). If you do see packets, move back to Nginx logs.
5. Dig Into Logs for Clues
  • Nginx access logs: tail -f /var/log/nginx/access.log—do you see your incoming requests here?
  • Nginx error logs: tail -f /var/log/nginx/error.log—look for proxy-related errors or configuration issues.
  • PM2 app logs: pm2 logs <your-app-name>—check if your app is receiving any requests or throwing errors when Nginx tries to connect.

If you're still stuck, share your full Nginx config, the output of pm2 list, and any relevant log snippets—this will help narrow down the problem faster!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 09:30:15