Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)
7.7 Combination 2 — Amazon Linux 2023 + Apache
sudo service nginx stop 2>/dev/null # free port 80 if Nginx was installed
sudo systemctl disable nginx 2>/dev/null
sudo yum install -y httpd
sudo service httpd start
sudo systemctl enable httpd
sudo tee /etc/httpd/conf.d/mysite.conf > /dev/null <<'EOF'
<VirtualHost *:80>
ServerName mysite.local
DocumentRoot /var/www/mysite
<Directory /var/www/mysite>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorDocument 404 /404.html
ErrorLog /var/log/httpd/mysite_error.log
CustomLog /var/log/httpd/mysite_access.log combined
</VirtualHost>
EOF
sudo apachectl configtest && sudo service httpd reload
curl -s http://localhost | head -5
How Apache picks the site
With name-based virtual hosts, the first <VirtualHost *:80> loaded is used for any request whose Host does not match another vhost. Since ours is the only vhost, it answers requests to the public IP too. Add ServerAlias www.example.com when you have a domain.