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:
- 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.
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 nginxin your SSH session. If it shows "inactive", start it withsystemctl start nginxand enable auto-start on boot withsystemctl enable nginx. - For Apache: Use
systemctl status httpd(orapache2on Debian/Ubuntu) and start it withsystemctl start httpdif it’s stopped. - For Node.js apps: Check if your app process is running with
pm2 list(if using PM2) orps aux | grep node. If it’s stopped, restart it withpm2 restart <your-app-name>ornode app.js(depending on your setup).
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
rootdirective in your site config (usually in/etc/nginx/sites-available/defaultor a custom config file). - For Apache: Look at the
DocumentRootin/etc/httpd/conf/httpd.confor/etc/apache2/sites-available/000-default.conf.
- For Nginx: Check the
- Navigate to that root directory via SSH (
cd /path/to/root) and list files withls -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.
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.
- Nginx: Check
- 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.
Even if you didn’t modify anything manually, automated processes might have caused issues:
- Check cron jobs: Run
crontab -lto 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.
Sometimes files exist, but the web server can’t access them due to incorrect permissions:
- In your app’s root directory, run
ls -lto check file owners and permissions. Web servers typically run aswww-data(Nginx/Apache) ornode(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
755and file permissions to644withchmod -R 755 /path/to/rootandchmod -R 644 /path/to/root/*.
内容的提问来源于stack exchange,提问作者Ricky

