
Ich versuche, Nginx als Proxyserver zwischen Client und Gunicorn zu verwenden. Nginx, Gunicorn (Django) sind Docker-Container. Das Problem ist, dass ich die Upstream-Pufferung nicht deaktivieren kann, wenn ich eine große Datei vom Client an die Django-App sende. Die TTFB-Zeit ist ziemlich kurz, daher wird mein Fortschrittsbalken (der das Ereignis xhr.upload.progress verwendet) sehr schnell zu 100 % (weniger als eine Sekunde). Dann muss ich 30 Sekunden warten, während die Datei auf den Server hochgeladen wird. Hier sind meine Einstellungen. Bitte helfen Sie. Ich habe viele Konfigurationen ausprobiert, um die Puffergröße auf Null usw. zu setzen, habe viele Antworten auf StackOverflow gelesen, aber nichts hilft.
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-Dockerdatei
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;
}
}