0Pricing
Flask Academy · Урок

Подключение 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:
      - web

Bring 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 --build

Quick 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. 🎉

Часто задаваемые вопросы

Урок «Подключение 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 включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Почему не стоит использовать встроенный сервер разработки
  2. Запуск Flask под Gunicorn
  3. Написание производственного Dockerfile
  4. Подключение Nginx и Compose
← Назад к Flask Academy