Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)
7.2 The hosting matrix
Six combinations may sound like a lot, but bagha — the idea is the same everywhere: files in a folder, a config that points to that folder, correct permissions, reload. Only paths and names change. Samjla ka?
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.