Linux Project 3 -Host Website with Nginx & Domain
Production-Level Project
Host Website with Nginx & Domain
Modern Web Architecture: High Performance & Scalable Setup
1. Why Nginx? (ELI5 Mode)
Think of Apache as a traditional waiter who handles one person at a time. Think of Nginx as a modern, high-speed robot that can handle thousands of customers simultaneously without getting tired.
Nginx aaj kal ka sabse popular web server hai. Ye bohot fast hai aur kam RAM use karta hai. Badi companies jaise Netflix aur Google bhi Nginx use karti hain.
👉 DevOps Tip: Production environment mein hum Nginx ko as a “Reverse Proxy” aur “Load Balancer” bhi use karte hain.
Step 1, 2 & 3: Initial Setup
2. Server & Connectivity
- Domain: Kisi bhi provider (GoDaddy/Namecheap) se domain lein.
- Server: AWS/VPS launch karein aur uska Public IP note karein.
ssh root@your-server-ip
Install Nginx:
sudo apt update && sudo apt install nginx -y
Step 4, 5 & 6: Data & Permissions
3. Web Directory & Website Files
Create a separate folder for your website to keep things organized. Set permissions so Nginx can read the files.
Har website ke liye ek alag folder banaiye. Permissions sahi hona zaroori hai taaki Nginx aapki website show kar sake.
sudo mkdir -p /var/www/sumitdevops.com/html
sudo chown -R $USER:$USER /var/www/sumitdevops.com/html
sudo chmod -R 755 /var/www/sumitdevops.com
sudo chown -R $USER:$USER /var/www/sumitdevops.com/html
sudo chmod -R 755 /var/www/sumitdevops.com
Create index.html:
nano /var/www/sumitdevops.com/html/index.html
Paste sample code: <h1>Nginx Server is Live!</h1>
Step 7, 8 & 9: Nginx Configuration
4. Server Block Configuration
Apache mein hum VirtualHost bolte hain, Nginx mein hum Server Block kehte hain.
sudo nano /etc/nginx/sites-available/sumitdevops.com
Add this configuration:
server {
listen 80;
server_name sumitdevops.com www.sumitdevops.com;
root /var/www/sumitdevops.com/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
listen 80;
server_name sumitdevops.com www.sumitdevops.com;
root /var/www/sumitdevops.com/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Enable Config & Restart:
sudo ln -s /etc/nginx/sites-available/sumitdevops.com /etc/nginx/sites-enabled/
sudo nginx -t # Syntax check karne ke liye
sudo systemctl restart nginx
sudo nginx -t # Syntax check karne ke liye
sudo systemctl restart nginx
Step 10 & 11: DNS & Verification
5. Mapping Domain & DNS
Go to your domain provider (GoDaddy). Add an ‘A’ record pointing to your Server Public IP.
Domain provider ke panel mein jayein aur ‘A Record’ add karein. Value mein server ki IP dalein. Isse domain ko pata chal jayega ki website kahan host hai.
👉 DNS Rule: Domain changes failne (propagate) mein kuch samay lagta hai. Chrome mein
Incognito mode use karein test ke liye.🛠️ 15 Real-World Troubleshooting Scenarios
1. Nginx Syntax Error?
Fix: Hamesha restart se pehle
Fix: Hamesha restart se pehle
sudo nginx -t chalayein. Ye line number bata dega jahan galti hai.
2. 403 Forbidden Error?
Fix: Check directory permissions. Nginx user (www-data) ke paas folder read karne ka access hona chahiye.
Fix: Check directory permissions. Nginx user (www-data) ke paas folder read karne ka access hona chahiye.
3. Website showing “Welcome to Nginx” default page?
Fix: Check karein ki
Fix: Check karein ki
sites-enabled mein link sahi hai ya nahi, aur default config ko remove karein: rm /etc/nginx/sites-enabled/default.
4. Port 80 not reachable?
Fix: Check Firewall:
Fix: Check Firewall:
sudo ufw allow 'Nginx Full'. Check AWS Security Group rules.
5. DNS not pointing?
Fix: Command chalayein
Fix: Command chalayein
dig yourdomain.com. Agar IP galat hai toh DNS record check karein.
[Total 15 high-level debugging cases included in full course]
Project Success: Site is Live! 🚀
Aapne successfully Nginx install kiya, Server Block configure kiya aur live domain ke sath connect kiya.
Summary: Nginx setup production mein speed aur reliability deta hai. Agle chapter mein hum seekhenge ise SSL (HTTPS) se secure karna.