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.
मित्रांनो, Ubuntu वर apt वापरतो, आणि इन्स्टॉल होताच सर्व्हिस आपोआप start होते – हा Amazon Linux पेक्षा मोठा फरक. त्याचबरोबर Ubuntu वर साइट फाइल्स sites-available मध्ये असतात आणि symlink ने enable होतात.
दोस्तों, Ubuntu पर apt इस्तेमाल करते हैं, और इंस्टॉल होते ही सर्विस अपने आप start हो जाती है – ये Amazon Linux से बड़ा फ़र्क है. साथ ही Ubuntu पर साइट फ़ाइलें sites-available में होती हैं और symlink से enable होती हैं.
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.
Ravindra Bagale's Tip – मराठी
खूप students Ubuntu वर ufw enable आधी चालवतात आणि SSH allow करायला विसरतात – मग server मधून बाहेर फेकले जातात आणि परत login होत नाही. आधी sudo ufw allow OpenSSH, मग बाकी rules, आणि शेवटी enable. आणि लक्षात ठेवा: EC2 वर security group हा आधीच firewall आहे.
Ravindra Bagale's Tip – हिंदी
बहुत students Ubuntu पर ufw enable पहले चला देते हैं और SSH allow करना भूल जाते हैं – फिर server से बाहर हो जाते हैं और दोबारा login नहीं होता. पहले sudo ufw allow OpenSSH, फिर बाकी rules, और आखिर में enable. और याद रखो: EC2 पर security group पहले से ही 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.