Score:1

How to disable upstream buffering Nginx + Docker + Gunicorn?

ph flag

I'm trying to use Nginx as proxy server between client and Gunicorn. Nginx, Gunicorn (Django) are Docker's containers. Problem is I can't disable buffering of upstream when I send large file from Client to Django App. TTFB time is quite small, thus my progress bar (which use xhr.upload.progress event) becomes 100% very fast (less than second). Then I have to wait 30 sec while file will be upload to server. Here are my settings. Please, help. I've tried many configurations trying to set buffer size to zero etc., check many answer on StackOverflow, but nothing helps.

docker-compose.yaml

...
    services:
  db:
    image: postgres:12.4
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    restart: always
    ports:
      - ${DB_PORT}:${DB_PORT}
    env_file:
      - ./.env

  backend:
    build: ./src/backend
    volumes:
      - RUDZASV0021:/code/storage/RUDZASV0021
      - logs:/code/logs
    restart: always
    depends_on:
      - db
    env_file:
      - ./.env

  nginx:
    build:
      context: .
      dockerfile: ./src/frontend/Dockerfile
    volumes:
      - ./docker-settings/default.conf:/etc/nginx/conf.d/default.conf:ro
    restart: always
    ports:
      - 80:80
      - 443:443
    depends_on:
      - backend

Backend Dockerfile

FROM python:3.8.7-slim

WORKDIR /code
COPY . .
RUN pip install -r /code/requirements.txt
RUN apt-get update && apt-get install -y mc
CMD gunicorn entrypoints.wsgi:application --workers=4 --worker-class=gevent  --timeout=90 --graceful-timeout=10 --bind 0.0.0.0:8000

Nginx Dockerfile

FROM nginx:1.20.0

WORKDIR /frontend
COPY ./src/frontend/dist .
WORKDIR /cert
COPY ./cert/device.key .
COPY ./cert/device.crt .

Nginx default.conf

upstream hello_django {
    server backend:8000 fail_timeout=0;
}

server {
    listen 80;
    return 301 https://$host$request_uri;
}

server {

    listen 443;

    ssl on;
    ssl_certificate /cert/device.crt;
    ssl_certificate_key /cert/device.key;

    client_max_body_size 2G;
    keepalive_timeout 5;

    access_log /frontend/nginx-access.log;
    error_log /frontend/nginx-error.log;

    location / {
        root /frontend;
        try_files $uri /index.html;
    }

    location /api/ {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_buffering off;
        proxy_request_buffering off;
        proxy_redirect off;
        proxy_pass http://hello_django;
    }

}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.