🚀 END-TO-END TUTORIAL: WEB SERVER USING NGINX¶
This tutorial includes:
1️⃣ Install NGINX
2️⃣ Set up file structure
3️⃣ Create a website
4️⃣ Configure NGINX server block
5️⃣ Enable & test
6️⃣ Deploy with firewall rules
7️⃣ Add HTTPS (SSL)
8️⃣ Logs + Monitoring
9️⃣ Performance tuning
✅ 1. Install NGINX¶
Ubuntu / Debian¶
Start + enable:
Check status:
Check default page:
Visit http://YOUR_SERVER_IP
✅ 2. Create Your Website Directory¶
You should not use /var/www/html.
Create your own folder:
Add sample site:
Paste:
Save → exit.
✅ 3. Create NGINX Server Block (Virtual Host)¶
Create a config file:
Paste this:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/mywebsite;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Replace
example.comwith your domain or public server IP.
✅ 4. Enable the Site¶
Enable the config file:
Disable the default site (optional but recommended):
Test configuration:
Reload:
Now your website lives at:
👉 http://your-domain
or
👉 http://your-server-ip
🔥 5. Setup Firewall (Important)¶
If using UFW:
🔒 6. Add HTTPS (Free SSL Certificate)¶
Use Certbot (Let's Encrypt):
Install Certbot:
Run:
Certbot will:
✔ Auto-configure HTTPS
✔ Auto-redirect HTTP → HTTPS
✔ Renew certificates automatically (cron job)
📁 7. NGINX Directory Structure Overview¶
| Path | Description |
|---|---|
/etc/nginx/nginx.conf |
Main config |
/etc/nginx/sites-available/ |
Virtual hosts (inactive) |
/etc/nginx/sites-enabled/ |
Active sites |
/var/www/mywebsite/ |
Website files |
/var/log/nginx/ |
Access + error logs |
📊 8. Logging + Monitoring¶
View access logs¶
View error logs¶
Basic monitoring command¶
⚡ 9. Performance Optimization Basics¶
Enable GZIP compression¶
Edit:
Add inside http {}:
Increase worker connections¶
Inside nginx.conf:
🎉 Deployment Completed!¶
✔ NGINX installed
✔ Website directory created
✔ Virtual host configured
✔ Firewall set
✔ HTTPS added
✔ Logs working
✔ Performance optimized