- 79 Views
- 13/11/2025
How to Install Nginx and Get Free SSL with Certbot on Ubuntu
Learn how to install Nginx on Ubuntu and secure your website with a free SSL certificate from Let’s Encrypt using Certbot. Step-by-step commands and configuration examples included for beginners and DevOps users.
1. Update System Packages
2. Install Nginx
Verify it’s running:
If it’s not active:
sudo systemctl enable nginx
Test in your browser:
3. Adjust Firewall (if using UFW):
sudo ufw enable
sudo ufw status
4. Add Your Website Configuration
Example config:
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
}
Enable it:
sudo nginx -t
sudo systemctl reload nginx
Create your web root:
sudo chown -R $USER:$USER /var/www/yourdomain.com
5. Install Certbot & SSL Plugin for Nginx
6. Obtain a Free SSL Certificate
Run the following:
Enter your email for urgent renewal/security notices.
Agree to the terms.
Choose whether to redirect HTTP → HTTPS (recommended: “2” for redirect).
Once complete, Certbot will automatically:
Get and install the SSL certificate
Edit your Nginx config for HTTPS
Reload Nginx
7. Test SSL Auto-Renewal
8. Verify HTTPS
Quick Summary
Step | Command / Description |
|---|---|
| Update system | sudo apt update && sudo apt upgrade -y |
| Install Nginx | sudo apt install nginx -y |
| Allow firewall | sudo ufw allow 'Nginx Full' |
| Install Certbot | sudo apt install certbot python3-certbot-nginx -y |
| Get SSL | sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com |
| Test renew | sudo certbot renew --dry-run |
Thank for visit my website
