
Nginx2026 में सबसे व्यापक रूप से उपयोग किया जाने वाला वेब सर्वर और रिवर्स प्रॉक्सी है। यह प्रति सेकंड लाखों अनुरोधों को संभालता है, एसएसएल को समाप्त करता है, लोड-बैलेंस बैकएंड करता है, और ओएस गति पर स्थिर फ़ाइलों को परोसता है। यह मार्गदर्शिका एसएसएल और कैशिंग के साथ इंस्टाल से लेकर उत्पादन कॉन्फ़िगरेशन तक नेग्नेक्स को कवर करती है।
📋 Table of Contents
Nginx इंस्टॉल करें
# Ubuntu/Debian
sudo apt install nginx
sudo systemctl enable nginx
sudo systemctl start nginx
# Check status
sudo nginx -t # test config
sudo systemctl status nginx
# Config location
ls /etc/nginx/sites-available/
बेसिक रिवर्स प्रॉक्सी
पोर्ट 80 से पोर्ट 8000 पर चल रहे आपके ऐप पर ट्रैफ़िक अग्रेषित करें।
# /etc/nginx/sites-available/myapp
server {
listen 80;
server_name example.com www.example.com;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
# Enable site
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
लेट्स एनक्रिप्ट के साथ एसएसएल (फ्री)
# Install Certbot
sudo apt install certbot python3-certbot-nginx
# Obtain and install SSL
sudo certbot --nginx -d example.com -d www.example.com
# Auto-renewal (already added to cron by certbot)
sudo certbot renew --dry-run
HTTPS और HTTP-टू-HTTPS रीडायरेक्ट जोड़ने के लिए Certbot स्वचालित रूप से आपके Nginx कॉन्फ़िगरेशन को संशोधित करता है।
एसएसएल के साथ पूर्ण उत्पादन कॉन्फिगरेशन
# HTTP -> HTTPS redirect
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
# HTTPS server
server {
listen 443 ssl http2;
server_name example.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
# Security headers
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header Strict-Transport-Security 'max-age=31536000' always;
# Proxy to app
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 60s;
proxy_connect_timeout 10s;
}
# Static files served directly by Nginx
location /static/ {
alias /var/www/myapp/static/;
expires 1y;
add_header Cache-Control 'public, immutable';
}
}
भार संतुलन
upstream myapp_backend {
least_conn; # send to least busy server
server 10.0.0.1:8000;
server 10.0.0.2:8000;
server 10.0.0.3:8000;
}
server {
listen 443 ssl http2;
location / {
proxy_pass http://myapp_backend;
}
}
दर सीमित करना
# In http block (nginx.conf)
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
# In server block
location /api/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://127.0.0.1:8000;
}
निष्कर्ष
Nginx एक कारण से उत्पादन मानक है – तेज़, स्थिर और लचीला। इसे किसी भी ऐप (FastAPI, Django, Node, Rails) के सामने रिवर्स प्रॉक्सी के रूप में उपयोग करें। निःशुल्क SSL के लिए Certbot जोड़ें, दर सीमित करने को कॉन्फ़िगर करें, और अधिकतम प्रदर्शन के लिए सीधे स्थिर फ़ाइलों की सेवा करें।
🔗 Share this article
✍️ Leave a Comment