Nginx كوكيل عكسي
وضع Gunicorn في الواجهة وتقديم الملفات الثابتة
Nginx كوكيل عكسي درس مجاني في Django Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Django Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Django Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why Add Nginx
Gunicorn runs your code, but it should not face the raw internet alone. A reverse proxy sits in front and shields it. 🛡️
What a Reverse Proxy Does
A reverse proxy receives every browser request, then forwards it to Gunicorn and relays the answer back. The client never talks to Gunicorn directly.
Nginx Is Fast at Files
Nginx excels at serving static files and handling thousands of connections, freeing Gunicorn to focus only on dynamic Python work.
The Two-Layer Stack
The flow becomes browser to Nginx to Gunicorn to Django. Each layer does what it is best at, giving you speed and safety together.
A Server Block
Nginx config lives in a server block. It listens on a port and names the domain it answers for.
server {
listen 80;
server_name example.com;
}Proxy to Gunicorn
Inside a location, proxy_pass tells Nginx where to send dynamic requests, usually Gunicorn on a local port or socket.
location / {
proxy_pass http://127.0.0.1:8000;
}Pass Real Headers
Add proxy_set_header lines so Django sees the true host and client IP, not just Nginx's local address.
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;Serve Static Directly
Map a location for /static/ to your collected files. Nginx serves them straight from disk, skipping Gunicorn entirely for speed.
location /static/ {
alias /app/staticfiles/;
}Where to Connect
Nginx can reach Gunicorn over a TCP port or a faster Unix socket. Sockets avoid network overhead on the same machine.
Test Before Reload
Always check your config with nginx -t before reloading. A bad file caught here saves you from taking the site offline.
nginx -t
systemctl reload nginxTLS Lives Here Too
Nginx is also the natural place to terminate HTTPS, decrypting traffic once before passing plain requests on to Gunicorn.
Quick Check
Pick the directive that forwards requests to Gunicorn.
Recap
You set up Nginx as a reverse proxy: it fronts Gunicorn with proxy_pass, serves static files fast, forwards headers, and handles HTTPS. 🎯
الأسئلة الشائعة
هل درس «Nginx كوكيل عكسي» مجاني؟
نعم — نص درس «Nginx كوكيل عكسي» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Django Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Django Academy 4 دروس في المجموع.
ماذا ستتعلم في «Nginx كوكيل عكسي»؟
وضع Gunicorn في الواجهة وتقديم الملفات الثابتة تتمرن على Django Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Django Academy؟
لا تُشترط خبرة سابقة. Django Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «Nginx كوكيل عكسي»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Django Academy هذا؟
نعم. كل درس في Django Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.