وضع Nginx في الواجهة واستخدام Compose
استخدم وكيلًا عكسيًا ونظّم المكدس.
وضع Nginx في الواجهة واستخدام Compose درس مجاني في Flask Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Flask Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Flask Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why Add Nginx
Gunicorn runs your app, but Nginx sits in front as a reverse proxy. It handles the messy public-facing work so Gunicorn can focus on Python. 🛡️
What a Reverse Proxy Does
A reverse proxy receives every client request first, then forwards it to Gunicorn and relays the response back out.
Nginx Serves Static Files
Let Nginx serve your CSS, JS, and images directly. It is far faster at shipping static files than Python ever will be.
TLS Lives Here Too
Nginx is the natural place to terminate HTTPS. It handles certificates and encryption, leaving Gunicorn to speak plain HTTP internally.
The proxy_pass Directive
In your Nginx config, proxy_pass tells it where to send traffic. You point it at the Gunicorn container by name and port.
location / {
proxy_pass http://web:8000;
}Enter Docker Compose
Docker Compose runs multiple containers together from one YAML file. Perfect for an app container plus an Nginx container.
Define the Web Service
In compose, your Flask image becomes the web service. Compose builds it from your Dockerfile and names it for other containers to reach.
services:
web:
build: .Add the Nginx Service
Add an nginx service that uses the official image and mounts your config file. It will publish ports to the outside world.
nginx:
image: nginx:alpine
ports:
- "80:80"They Talk by Service Name
Compose puts both containers on one network. Nginx reaches Gunicorn at http://web:8000 using the service name as the host.
Control Startup Order
Use depends_on so Nginx starts after web. It does not wait for readiness, but it sets a sensible boot sequence.
depends_on:
- webBring the Stack Up
One command launches everything. docker compose up builds, networks, and starts both services as a single running stack.
docker compose up -d --buildQuick Check
What is Nginx doing in front of Gunicorn?
Recap
Nginx fronts Gunicorn, and Compose wires both into one stack you launch with a single command. You can now ship Flask to production. 🎉
تعلم Python مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 30
- الدروس
- 120
الأسئلة الشائعة
هل درس «وضع Nginx في الواجهة واستخدام Compose» مجاني؟
نعم — نص درس «وضع Nginx في الواجهة واستخدام Compose» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Flask Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Flask Academy 4 دروس في المجموع.
ماذا ستتعلم في «وضع Nginx في الواجهة واستخدام Compose»؟
استخدم وكيلًا عكسيًا ونظّم المكدس. تتمرن على Flask Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Flask Academy؟
لا تُشترط خبرة سابقة. Flask Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «وضع Nginx في الواجهة واستخدام Compose»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Flask Academy هذا؟
نعم. كل درس في Flask Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- لماذا لا تستخدم خادم التطوير المضمّن
- تشغيل Flask باستخدام Gunicorn
- كتابة Dockerfile للإنتاج
- وضع Nginx في الواجهة واستخدام Compose