Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)
7.2 The hosting matrix
Six combinations may sound like a lot, but look – the idea is the same everywhere: files in a folder, a config that points to that folder, correct permissions, and reload. Only paths and names change. Got it?
सहा कॉम्बिनेशन्स खूप वाटतात, पण बघा – आयडिया सगळीकडे एकच आहे: फाइल्स एका फोल्डरमध्ये, त्या फोल्डरकडे पॉइंट करणारा कॉन्फिग, बरोबर परमिशन्स, आणि reload. फक्त पाथ्स आणि नावं बदलतात. समजलं का?
छह कॉम्बिनेशन्स बहुत लगते हैं, लेकिन देखो – आइडिया हर जगह एक ही है: फ़ाइलें एक फ़ोल्डर में, उस फ़ोल्डर की तरफ़ पॉइंट करने वाला कॉन्फ़िग, सही परमिशन्स, और reload. सिर्फ़ पाथ्स और नाम बदलते हैं. समझ आया?
We will host the same site in all six combinations. All six use a dedicated folder /var/www/mysite and a virtual host (server block), which is the professional way. A quick "default root" method is also shown.
| OS | Web server | Install | Site config file | Document root used | Web-server user | Extra step |
|---|---|---|---|---|---|---|
| Amazon Linux 2023 | Nginx | yum install nginx |
/etc/nginx/conf.d/mysite.conf |
/var/www/mysite |
nginx |
— |
| Amazon Linux 2023 | Apache | yum install httpd |
/etc/httpd/conf.d/mysite.conf |
/var/www/mysite |
apache |
— |
| Ubuntu 22.04/24.04 | Nginx | apt install nginx |
/etc/nginx/sites-available/mysite + symlink |
/var/www/mysite |
www-data |
disable default site |
| Ubuntu 22.04/24.04 | Apache | apt install apache2 |
/etc/apache2/sites-available/mysite.conf |
/var/www/mysite |
www-data |
a2ensite, a2dissite 000-default |
| CentOS Stream 9 | Nginx | yum install nginx |
/etc/nginx/conf.d/mysite.conf |
/var/www/mysite |
nginx |
firewalld, restorecon |
| CentOS Stream 9 | Apache | yum install httpd |
/etc/httpd/conf.d/mysite.conf |
/var/www/mysite |
apache |
firewalld, restorecon |
Default document roots (quick method — just copy files here): Nginx on AL2023/CentOS → /usr/share/nginx/html; Nginx on Ubuntu → /var/www/html; Apache on all three → /var/www/html.
Pre-requisites for every combination
- EC2 instance running, security group allows TCP 80 (and 443 later) from
0.0.0.0/0and TCP 22 from your IP. - You are logged in via SSH as
ec2-user(AL2023/CentOS) orubuntu(Ubuntu). - Only one web server runs on port 80. If you installed both, stop and disable the other one.
Ravindra Bagale's Tip
Many students install both Nginx and Apache on the same server and start both – then the second one gives Address already in use. One web server per port 80. If you don't need the other one, run sudo service httpd stop and sudo systemctl disable httpd (or nginx).
Ravindra Bagale's Tip – मराठी
खूप students एकाच server वर Nginx आणि Apache दोन्ही install करून दोन्ही start करतात – मग दुसरा Address already in use देतो. एका port 80 वर एकच web server. दुसरा नको असेल तर sudo service httpd stop आणि sudo systemctl disable httpd (किंवा nginx) करा.
Ravindra Bagale's Tip – हिंदी
बहुत students एक ही server पर Nginx और Apache दोनों install करके दोनों start कर देते हैं – फिर दूसरा Address already in use देता है. एक port 80 पर एक ही web server. दूसरा नहीं चाहिए तो sudo service httpd stop और sudo systemctl disable httpd (या nginx) करो.
Lab
Chala, ya matrix madhun tumchya EC2 cha combination nivda aani tya row madhla site config file, document root aani web-server user liha. Mag sudo ss -tlnp | grep :80 ne port 80 mokla aahe ka te check kara.