Ravindra BagaleCourses & study guides

Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)

7.14 Troubleshooting static sites

Kalji karu naka if you see errors here — every student sees them. What matters is fixing them calmly, one check at a time.

Symptom Likely cause Fix
Browser spins then timeout Security group missing port 80; firewalld blocking; no public IP Add inbound HTTP 80 from 0.0.0.0/0; firewall-​cmd --​add-​service=​http; check public IP
Connection refused Web server not running / listening on another port sudo service nginx status; sudo ss -tlnp
Still shows default welcome page Your vhost not loaded or another block wins Ubuntu: remove sites-​enabled/​default; AL/CentOS: check server_name; sudo nginx -T shows full config
403 Forbidden No index.html; wrong permissions; SELinux label; Require missing ls -la; chmod 755 dirs / 644 files; restorecon -Rv; namei -​l /​var/​www/​mysite/​index.​html
404 Not Found Wrong root/DocumentRoot; filename case (Index.html) Check config path; ls exact names; check error log
CSS/images not loading Wrong relative path; file not uploaded Open browser DevTools (F12) → Network tab
502 Bad Gateway (Reverse proxy only) backend app down See Chapter 10
Config change has no effect Forgot to reload; syntax error sudo nginx -​t && sudo service nginx reload
Site broke after stop/start Public IP changed Use Elastic IP; update server_name
nginx: [emerg] bind() to 0.​0.​0.​0:​80 failed (98: Address in use) Apache (or another Nginx) already on port 80 sudo ss -​tlnp | grep :​80; stop the other server

Golden troubleshooting commands:

curl -I http://localhost                      # does it work from inside the server?
sudo ss -tlnp | grep -E ':80|:443'            # who is listening?
sudo tail -n 30 /var/log/nginx/error.log      # Nginx errors
sudo tail -n 30 /var/log/httpd/error_log      # Apache errors (AL2023 / CentOS)
sudo tail -n 30 /var/log/apache2/error.log    # Apache errors (Ubuntu)
namei -l /var/www/mysite/index.html           # permissions of every folder in the path

Inside works, outside doesn't?

If curl http://localhost works on the server but the browser cannot open http://<PUBLIC_IP>, the problem is outside the web server: security group, firewalld, NACL, public IP, or you typed https.