Django + Nginx大文件上传

时间:2019-03-21 14:55:09

标签: django nginx

我正在尝试使用nginx在django中上传2GB的文件。该文件上传到100%,然后突然终止,并且在Nginx中显示502 Bad Gateway错误。

下面是我的应用程序配置

upstream app_server {
    server unix:/home/training/run/gunicorn.sock fail_timeout=0;
}

server {
    listen 80;

    # add here the ip address of your server
    # or a domain pointing to that ip (like example.com or www.example.com)
    server_name training.academy;

    keepalive_timeout 30;
    client_max_body_size 4G;

    access_log /home/training/logs/nginx-access.log;
    error_log /home/training/logs/nginx-error.log;

    location /static/ {
        alias /home/training/trainingapp/static/;
    }

    location /media/ {
        alias /home/training/trainingapp/media/;
    }

    # checks for static file, if not found proxy to app
    location / {
        try_files $uri @proxy_to_app;
    }

    location @proxy_to_app {
      proxy_read_timeout 1200;
      proxy_connect_timeout 1200;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $host;
      proxy_redirect off;
      proxy_pass http://app_server;
      proxy_intercept_errors on;
    }
}

下面是gunicorn启动配置

#!/bin/bash

NAME="training"
DIR=/home/training/trainingapp
USER=training
GROUP=training
WORKERS=300
TIMEOUT=1200
BIND=unix:/home/training/run/gunicorn.sock
DJANGO_SETTINGS_MODULE=training.settings
DJANGO_WSGI_MODULE=training.wsgi
LOG_LEVEL=error

cd $DIR
source ../bin/activate

export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DIR:$PYTHONPATH

exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $WORKERS \
  --user=$USER \
  --group=$GROUP \
  --bind=$BIND \
  --log-level=$LOG_LEVEL \
  --log-file=-

如何纠正此错误,以便我可以完整完整地上传文件而不是502错误?

0 个答案:

没有答案