
我正在嘗試使用 Nginx 作為客戶端和 Gunicorn 之間的代理伺服器。 Nginx、Gunicorn (Django) 是 Docker 的容器。問題是當我從客戶端發送大檔案到 Django 應用程式時,我無法停用上游緩衝。 TTFB 時間非常小,因此我的進度條(使用 xhr.upload.progress 事件)變得非常快(小於秒)100%。然後我必須等待 30 秒,檔案才會上傳到伺服器。這是我的設定。請幫忙。我嘗試了許多配置,試圖將緩衝區大小設為零等,檢查了 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 Dockerfile
FROM nginx:1.20.0
WORKDIR /frontend
COPY ./src/frontend/dist .
WORKDIR /cert
COPY ./cert/device.key .
COPY ./cert/device.crt .
Nginx 預設.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;
}
}