
클라이언트와 Gunicorn 사이의 프록시 서버로 Nginx를 사용하려고 합니다. Nginx, Gunicorn(Django)은 Docker의 컨테이너입니다. 문제는 클라이언트에서 Django 앱으로 대용량 파일을 보낼 때 업스트림 버퍼링을 비활성화할 수 없다는 것입니다. TTFB 시간은 매우 작기 때문에 xhr.upload.progress 이벤트를 사용하는 진행률 표시줄이 100% 매우 빨라집니다(초 미만). 그런 다음 파일이 서버에 업로드될 때까지 30초를 기다려야 합니다. 내 설정은 다음과 같습니다. 도와주세요. 버퍼 크기를 0으로 설정하려고 많은 구성을 시도했지만 StackOverflow에서 많은 답변을 확인했지만 아무 도움이 되지 않습니다.
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
백엔드 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 도커파일
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;
}
}