Ravindra BagaleCourses & study guides मराठी Track your progress

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?

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

  1. EC2 instance running, security group allows TCP 80 (and 443 later) from 0.0.0.0/0 and TCP 22 from your IP.
  2. You are logged in via SSH as ec2-user (AL2023/CentOS) or ubuntu (Ubuntu).
  3. 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).

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.