7. Apache and Nginx: Install and Understand
7.4 Installing Nginx and Apache on Ubuntu
Ubuntu var apt install kelyavar service aapoaap start hote – pan enable karun ghene changli savay.
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
Ubuntu var ufw enable kela aani aadhi SSH allow kela nahi tar tumhi swatahlach server madhun baher kadhta – khup students ne asa kela aahe. Aadhi sudo ufw allow OpenSSH, mag web rule, mag enable. Kram lakshat theva.
Lab
On your Ubuntu instance install Nginx, check the symlink in sites-enabled, then install Apache on a second Ubuntu instance (or after stopping Nginx) and list enabled sites with ls /etc/apache2/sites-enabled.