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

Chapter 6: Web Servers — Nginx and Apache

6.5 Ubuntu 22.04 / 24.04

Friends, on Ubuntu we use apt, and the service starts automatically right after install – a big difference from Amazon Linux. Also, on Ubuntu the site files live in sites-available and are enabled with a symlink.

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).

Ravindra Bagale's Tip

Many students run ufw enable first on Ubuntu and forget to allow SSH – then they are locked out of the server and cannot log in again. First sudo ufw allow OpenSSH, then the other rules, and enable last. And remember: on EC2 the security group is already a firewall.

Lab

Chala, Ubuntu instance var Nginx install karun ls -l /etc/nginx/sites-enabled/ chalva aani default symlink kuthe point karto te liha. Mag sudo ufw status ne ufw inactive aahe ka te bagha – enable karu naka, fakt status check kara.