Common errors, likely causes and fixes
Debug in layers instead of changing random settings. Check the error first, then change one thing at a time.
Common Errors, Likely Causes and Fixes
10 DIAGNOSTIC SCENARIOSWhen a command or connection fails, find the observed symptom below to identify the most probable layer of failure and test the recommended corrective action.
| SYMPTOM | POSSIBLE CAUSE | WHAT TO TRY |
|---|---|---|
| SSH connection times out | Port 22 is blocked, the administrator's source IP has changed, or the instance is not reachable through its public address or network route. | Check the security group's SSH source rule, verify the current public IP address, confirm subnet route table points to an Internet Gateway, and verify you are connecting from the approved administration network. Confirm that the instance state is Running and its status checks have passed. |
| Permission denied (publickey) | The wrong private key is being used, the SSH username is incorrect, or private-key file permissions are too permissive. | Verify the key-pair name associated with the EC2 instance in the AWS Console. Use the correct .pem file and username (for Amazon Linux 2023, the default username is ec2-user). On macOS and Linux, set read-only permissions with chmod 400 ~/Downloads/aws-class-key.pem. Ensure the file path matches your local filesystem. Windows users using PowerShell or OpenSSH must also ensure only their current user account has read access. |
| Website times out | HTTP is blocked, the instance does not have the expected public IPv4 connectivity, or subnet routing is not configured for internet access. | Check that your Security Group has an inbound rule for TCP port 80 from 0.0.0.0/0 (Anywhere IPv4). Verify the instance's active Public IPv4 address in the EC2 Console, and verify the subnet route table directs 0.0.0.0/0 to an Internet Gateway (igw-...). Do not open every port or disable firewalls. |
| Connection refused on port 80 | Nginx is stopped, has failed to start, or is not listening on the expected interface and port. | Check the Nginx service status with sudo systemctl status nginx, inspect recent error logs, and check listening ports with sudo ss -tulpn | grep :80. Start or restart Nginx only after inspecting the reported condition. |
| Nginx welcome page appears | The starter website files have not been copied to the configured document root, or the expected index.html was not replaced. | Confirm that /usr/share/nginx/html/index.html contains your intended website files rather than the default package page. Verify the document root files with ls -la /usr/share/nginx/html, re-copy the deployed repository files, and run sudo systemctl reload nginx. |
| 403 Forbidden | The requested content is unavailable because of file permissions, directory permissions, missing index configuration, or a server access rule. | Check the requested file path and document root. Ensure files have readable permissions (chmod 644) and directories have traversal/executable permissions (chmod 755). Inspect /var/log/nginx/error.log for the exact denial reason. Do not solve permission problems by recursively granting unrestricted write access (e.g. avoid chmod 777). |
| 404 Not Found | The requested path or filename is incorrect, or the file is missing from the deployed directory. | Check the exact URL in your browser, filename capitalization (Linux filesystems are strictly case-sensitive), deployment directory location, and relative paths referenced in the HTML. Confirm the requested file actually exists in /usr/share/nginx/html/. |
| CSS or images are missing | Asset paths are incorrect, filename capitalization does not match, or the required files were not copied. | Open browser Developer Tools (F12) to inspect the Network tab for red 404 responses. Compare requested asset paths against the actual directory structure and exact filenames in /usr/share/nginx/html/. |
| git clone fails | The repository URL is incorrect, the repository is unavailable, GitHub access is blocked, or a private repository requires authorization. | Check the repository URL and branch name. Verify network connectivity from EC2 to GitHub. If using a private repository, use an approved personal access token or SSH deploy key. Never put access tokens or private credentials into public files, GitHub commits, or screenshots. |
| 502 Bad Gateway | A reverse proxy cannot reach its upstream application or backend. | Check the upstream application process, reverse proxy configuration (proxy_pass), and service logs. Note that this error is not part of a standard static Nginx deployment because our workshop serves static files directly from disk without an application backend. A 502 can have different causes depending on architecture; investigate upstream communication rather than assuming a single cause. |
AWS Troubleshooting Note
AWS has an official troubleshooting guide for SSH and connectivity failures. Use it to investigate the specific error instead of repeatedly opening network ports broadly.
Rule of thumb: Opening ports to 0.0.0.0/0 when debugging rarely fixes an underlying configuration or authentication problem, but it introduces immediate security risk.
EC2 Connection Troubleshooting
The AWS Documentation provides comprehensive runbooks for instance reachability, VPC internet routing, and key-pair troubleshooting. Consult these official references when isolating complex connection failures:
Troubleshooting Connecting to Your EC2 Instance
Step-by-step diagnostic workflows for connection refused, connection timed out, Host key verification failed, and Permission denied (publickey).
