Ravindra BagaleCourses & study guides

Chapter 6: Web Servers — Nginx and Apache

6.5 Ubuntu 22.04 / 24.04

Nginx on Ubuntu

sudo apt update
sudo apt install -y nginx
sudo service nginx start
sudo systemctl enable nginx          # already started by apt, this makes sure
sudo service nginx status
sudo nginx -t
curl -I http://localhost
ls /var/www/html                           # contains index.nginx-debian.html
ls -l /etc/nginx/sites-enabled/            # 'default' -> ../sites-available/default

Apache on Ubuntu

sudo apt update
sudo apt install -y apache2
sudo service apache2 start
sudo systemctl enable apache2
sudo service apache2 status
sudo apache2ctl configtest
curl -I http://localhost

Useful Ubuntu-only Apache helpers:

Command Purpose
sudo a2ensite mysite.​conf / a2dissite Enable / disable a virtual host
sudo a2enmod rewrite proxy proxy_​http / a2dismod Enable / disable modules
sudo a2enconf / a2disconf Enable / disable extra config snippets

Ubuntu firewall (ufw)

ufw is inactive by default on Ubuntu EC2 AMIs — the AWS security group is your firewall. If you enable ufw, allow SSH first or you will lock yourself out: sudo ufw allow OpenSSH && sudo ufw allow 'Nginx Full' && sudo ufw enable (use 'Apache Full' for Apache).