13. Multiple Websites on One Server and HTTPS with Certbot
13.1 How Name-Based Virtual Hosting Works
Ekach IP, ekach port 80 – mag server la kasa kalte konti site dakhvaychi? Browser pratyek request madhe Host: header pathavto. Web server to header server_name / ServerName shi julavto.
Browser: GET / HTTP/1.1 Host: site1.yourdomain.com ─┐
Browser: GET / HTTP/1.1 Host: site2.yourdomain.com ─┼─► 203.0.113.10:80 ─► match Host
Scanner: GET / HTTP/1.1 Host: 203.0.113.10 ─┘ │
├─ site1 → /var/www/site1
├─ site2 → /var/www/site2
└─ no match → default site
Why this matters for security
Scanners and bots usually connect by IP, not by name. If your default site is a real application, every internet scanner sees it. A catch-all default that returns nothing (Nginx return 444) hides your real sites from IP-based scanning and blocks Host-header tricks.
Ravindra Bagale's Tip
You created two sites and the same site shows on both – a common problem for students. The reason is that server_name doesn't match and the default site wins. Use sudo nginx -T | grep server_name or sudo apachectl -S to see which file answers for which name.
Ravindra Bagale's Tip – मराठी
दोन sites बनवल्या आणि दोन्हीवर एकच site दिसते – बऱ्याच students चा problem. कारण server_name जुळत नाही आणि default site जिंकते. sudo nginx -T | grep server_name किंवा sudo apachectl -S ने कोणत्या नावाला कोणती file उत्तर देते ते बघा.
Ravindra Bagale's Tip – हिंदी
दो sites बनाईं और दोनों पर एक ही site दिखती है – बहुत से students की problem. वजह यह है कि server_name मेल नहीं खाता और default site जीत जाती है. sudo nginx -T | grep server_name या sudo apachectl -S से देखो कि किस नाम का जवाब कौन सी file देती है.
Practice task
Use curl -v http://example.com -o /dev/null and find the Host header your client sends.