🌐 Detecting your location…
📢 Advertisement — Configure AdSense in Appearance → Customize → AdSense Settings

دليل الوكيل العكسي لـ Nginx 2026: SSL وموازنة التحميل وإعداد الإنتاج

⏱️2 min read  ·  329 words
Nginx Reverse Proxy Guide 2026: SSL, Load Balancing and Production Setup

نجينكسهو خادم الويب والوكيل العكسي الأكثر استخدامًا في عام 2026. فهو يتعامل مع ملايين الطلبات في الثانية، وينهي طبقة المقابس الآمنة (SSL)، ويوازن تحميل الواجهات الخلفية، ويقدم الملفات الثابتة بسرعات نظام التشغيل. يغطي هذا الدليل Nginx بدءًا من التثبيت وحتى تكوين الإنتاج باستخدام SSL والتخزين المؤقت.

تثبيت إنجينكس

# 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

SSL مع Let’s Encrypt (مجاني)

# 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

يقوم Certbot تلقائيًا بتعديل تكوين Nginx الخاص بك لإضافة إعادة توجيه HTTPS وHTTP-to-HTTPS.

تكوين الإنتاج الكامل مع SSL

# 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). أضف Certbot للحصول على SSL مجاني، وقم بتكوين حدود المعدل، وقم بخدمة الملفات الثابتة مباشرة لتحقيق أقصى قدر من الأداء.

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *

🌐 Read in:🇬🇧 English🇩🇪 Deutsch🇧🇷 Português🇸🇦 العربية🇮🇳 हिन्दी🇧🇩 বাংলা