Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)
7.14 Troubleshooting static sites
Don't worry if you see errors here – every student gets them. What matters is fixing them calmly, one check at a time.
इथे errors आले तर काळजी करू नका – प्रत्येक स्टुडंटला येतात. महत्त्वाचं आहे ते शांतपणे, एक एक चेक करून सोडवणं.
यहाँ errors आएँ तो चिंता मत करो – हर स्टूडेंट को आते हैं. ज़रूरी ये है कि उन्हें शांति से, एक-एक चेक करके सुलझाओ.
| 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.
Ravindra Bagale's Tip
Many students change three things at once when a problem comes up, and then never know what fixed it. One change, then test, then the next change. And every time, start with curl -I http://localhost from inside – first decide whether it works from inside or from outside.
Ravindra Bagale's Tip – मराठी
खूप students problem आला की एकाच वेळी तीन गोष्टी बदलतात, आणि मग कशाने fix झाला ते कळतच नाही. एक बदल, मग test, मग पुढचा बदल. आणि प्रत्येक वेळी आधी आतून curl -I http://localhost – आतून चालतं का बाहेरून, हे आधी ठरवा.
Ravindra Bagale's Tip – हिंदी
बहुत students problem आने पर एक साथ तीन चीज़ें बदल देते हैं, और फिर पता ही नहीं चलता कि fix किससे हुआ. एक बदलाव, फिर test, फिर अगला बदलाव. और हर बार पहले अंदर से curl -I http://localhost – अंदर से चलता है या बाहर से, यह पहले तय करो.
Lab
Chala, muddam security group madhun port 80 cha rule kadha aani browser madhe timeout bagha. Server var curl -I http://localhost 200 deto ka te check kara, mag rule parat add karun site parat ughadte ka te bagha.