Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)
7.12 Hosting multiple sites on one server (virtual hosts)
Think of one building with many shops: the building has one address (IP), but each shop has its own name board (domain). Technically, the browser sends the domain in the HTTP Host header, and the web server picks the matching server_name / ServerName block. Mauli Dairy's order site and blog on one server work exactly this way.
एक बिल्डिंग, अनेक दुकानं असं समजा: बिल्डिंगचा पत्ता एक (IP), पण प्रत्येक दुकानाचा नावाचा बोर्ड वेगळा (डोमेन). टेक्निकली, ब्राउझर HTTP Host हेडरमध्ये डोमेन पाठवतो, आणि वेब सर्व्हर जुळणारा server_name / ServerName ब्लॉक निवडतो. Mauli Dairy ची ऑर्डर साइट आणि ब्लॉग एकाच सर्व्हरवर – याच पद्धतीने.
एक बिल्डिंग, कई दुकानें ऐसा समझो: बिल्डिंग का पता एक (IP), लेकिन हर दुकान का नाम बोर्ड अलग (डोमेन). टेक्निकली, ब्राउज़र HTTP Host हेडर में डोमेन भेजता है, और वेब सर्वर मैच होने वाला server_name / ServerName ब्लॉक चुनता है. Mauli Dairy की ऑर्डर साइट और ब्लॉग एक ही सर्वर पर – इसी तरीके से.
One server can host many websites; the web server chooses the site by the Host header (domain name) sent by the browser.
site1.example.com ─┐ ┌─► /var/www/site1
├─► 13.233.10.25:80 ────┤
site2.example.com ─┘ (one IP, one port) └─► /var/www/site2
# Nginx: one server block per site
server { listen 80; server_name site1.example.com; root /var/www/site1; }
server { listen 80; server_name site2.example.com; root /var/www/site2; }
# Apache: one VirtualHost per site
<VirtualHost *:80>
ServerName site1.example.com
DocumentRoot /var/www/site1
</VirtualHost>
<VirtualHost *:80>
ServerName site2.example.com
DocumentRoot /var/www/site2
</VirtualHost>
Point both domains' DNS A records to the server's Elastic IP (allocate and attach it as in section 5.5; details in section 14.1). Buying a domain and creating these records step by step is covered in Chapter 9. Without real domains you can test from your laptop by adding a line 13.233.10.25 site1.example.com to your hosts file (/etc/hosts on Linux/Mac, C:\Windows\System32\drivers\etc\hosts on Windows), or with curl -H "Host: site1.example.com" http://13.233.10.25.
Ravindra Bagale's Tip
For projects you want to show in an interview or put on your resume, spend a little money on a domain and add HTTPS with certbot. A link like https://yourname.dev looks far more professional than http://13.233.x.x. Just don't forget to attach an Elastic IP first, so the DNS record never breaks.
Ravindra Bagale's Tip – मराठी
Interview मध्ये दाखवायच्या किंवा resume वर टाकायच्या projects साठी थोडे पैसे खर्चून domain घ्या आणि certbot ने HTTPS लावा. https://yourname.dev सारखी link http://13.233.x.x पेक्षा खूप professional दिसते. फक्त आधी Elastic IP attach करायला विसरू नका, म्हणजे DNS record कधीच तुटणार नाही.
Ravindra Bagale's Tip – हिंदी
Interview में दिखाने वाले या resume पर डालने वाले projects के लिए थोड़े पैसे खर्च करके domain लो और certbot से HTTPS लगाओ. https://yourname.dev जैसा link http://13.233.x.x से कहीं ज़्यादा professional दिखता है. बस पहले Elastic IP attach करना मत भूलो, ताकि DNS record कभी न टूटे.
Lab
Chala, /var/www/site1 aani /var/www/site2 banva, donhi sathi server blocks liha, aani curl -H "Host: site1.example.com" http://localhost aani curl -H "Host: site2.example.com" http://localhost ne donhi vegle pages distat ka te check kara.