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

AWS EC2上JavaScript应用资源缺失致空白页的排查求助

Hey Ricky, let's break this down step by step to get your JavaScript app back up and running. Since you have full EC2 access and know your way around AWS, these checks should be straightforward even with limited server/JS knowledge:

1. First, confirm your EC2 instance is healthy and reachable
  • Head to the AWS EC2 Console and check your instance's Status Checks (both system and instance status should show "OK"). If not, you might need to reboot the instance or investigate underlying hardware issues.
  • Try SSH-ing into your EC2 instance to ensure it’s responsive. If you can’t connect, verify your security groups allow inbound SSH traffic (port 22) from your IP, and the instance’s public IP/DNS hasn’t changed unexpectedly.
2. Verify your web server or app process is running

Most JS apps rely on a web server (like Nginx/Apache) or a process manager (like PM2 for Node.js apps) to serve content. Let’s check:

  • For Nginx: Run systemctl status nginx in your SSH session. If it shows "inactive", start it with systemctl start nginx and enable auto-start on boot with systemctl enable nginx.
  • For Apache: Use systemctl status httpd (or apache2 on Debian/Ubuntu) and start it with systemctl start httpd if it’s stopped.
  • For Node.js apps: Check if your app process is running with pm2 list (if using PM2) or ps aux | grep node. If it’s stopped, restart it with pm2 restart <your-app-name> or node app.js (depending on your setup).
3. Check the web server’s root directory for missing resources

The "resource not found" errors mean the server can’t locate the files your HTML is trying to load. Let’s verify the files exist:

  • Find your web server’s root directory:
    • For Nginx: Check the root directive in your site config (usually in /etc/nginx/sites-available/default or a custom config file).
    • For Apache: Look at the DocumentRoot in /etc/httpd/conf/httpd.conf or /etc/apache2/sites-available/000-default.conf.
  • Navigate to that root directory via SSH (cd /path/to/root) and list files with ls -la. Check if the missing resources (the ones flagged in your Web Inspector console) exist here. If they’re gone, an accidental deletion, failed deployment, or cleanup script might have removed them.
4. Dig into logs to find the root cause

Logs will give you concrete details about why resources are missing or the server is failing:

  • Web server error logs:
    • Nginx: Check /var/log/nginx/error.log
    • Apache: Check /var/log/httpd/error_log (RHEL/CentOS) or /var/log/apache2/error.log (Debian/Ubuntu)
      Look for lines like "404 Not Found" with the missing file paths—this might reveal typos in your HTML’s resource paths or permission issues.
  • App logs (for Node.js): If your app runs on Node, check the log file specified in your PM2 config or where you redirect output (e.g., app.log).
  • EC2 System Log: In the EC2 Console, go to your instance > Actions > Monitor and troubleshoot > Get system log. This can show system-level issues like out-of-memory errors that crashed your server or app.
5. Check for unintended automated changes

Even if you didn’t modify anything manually, automated processes might have caused issues:

  • Check cron jobs: Run crontab -l to see if any scheduled tasks could delete files or restart services unexpectedly.
  • If you use CI/CD tools (like GitHub Actions, Jenkins) to deploy your app, check recent deployment logs. A failed deploy might have overwritten or deleted your static files.
6. Fix file permissions (if resources exist but are inaccessible)

Sometimes files exist, but the web server can’t access them due to incorrect permissions:

  • In your app’s root directory, run ls -l to check file owners and permissions. Web servers typically run as www-data (Nginx/Apache) or node (Node.js apps).
  • If the owner is wrong, fix it with chown -R www-data:www-data /path/to/root (replace with your server’s user/group).
  • Ensure files have read permissions for the server user: Set directory permissions to 755 and file permissions to 644 with chmod -R 755 /path/to/root and chmod -R 644 /path/to/root/*.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 11:32:38