繁体   English   中英

Django + Nginx + Gunicorn“对等重置连接”错误

[英]Django+Nginx+Gunicorn “Connection reset by peer” Error

我正在使用Digital Ocean教程( 在此处 )设置一个允许文件上传的应用程序(视频范围从5 mb到1 GB)。 我知道上传大文件不是理想的用例,但是客户端和服务器位于通过LAN连接的相邻建筑物中(传输速度很快),而FTP并不是我提供的选项。

当文件足够小(30-40 mb)时,该应用程序可以正常工作。 在100 mb +的视频中,客户端出现“ 502-错误的网关”错误。

Nginx错误日志显示以下内容:

2017/07/17 15:52:18 [error] 18503#18503: *9 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: <client-ip>, server: <my-hostname>, request: "POST /videos HTTP/1.1", upstream: "http://unix:/www/app/app.sock:/videos", host: "<my-hostname>", referrer: "<app-domain>/videos"

Gunicorn错误日志未显示任何错误。

我的Gunicorn设置:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=django
Group=www-data
WorkingDirectory=/www/app
EnvironmentFile=/www/app/.env2 
ExecStart=/home/django/.pyenv/versions/django/bin/gunicorn --access-logfile /backup/logs/app_gunicorn_access.log --error-logfile /backup/logs/app_gunicorn_errors.log --workers 3 --worker-class=tornado  --timeout=600 --graceful-timeout=10 --log-level=DEBUG --capture-output --bind unix:/www/app/app.sock app.wsgi:application

[Install]
WantedBy=multi-user.target

我究竟做错了什么?

编辑->

NGINX配置

server {
    listen 80;
    server_name <my-hostname>;
    rewrite ^/(.*) https://<my-domain>/$1 permanent;
}

server {
    listen 443 ssl;
    proxy_read_timeout 600s;
    keepalive_timeout 5;
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    server_name <my-hostname>;
    client_max_body_size 0;

    ssl_certificate /ssl_certs/hostname_bundle.cer;
    ssl_certificate_key /ssl_certs/hostname.key;

    root /www/app;

    location = /favicon.ico { access_log off; log_not_found off; }

    location /static/ {
        alias /www/app/staticfiles/;
    }

    location /media/ {
        alias /backup/app_media/;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/www/app/app.sock;
        include  /etc/nginx/mime.types;
    }

    location /robots.txt {
        alias /www/app/robots.txt;
    } 
}

通过将工作人员类别从龙卷风更改为默认(同步)工作人员,同时将超时时间保持足够长的时间来完成大型上传,从而解决了该问题。 显然,对于这个问题可能有更优雅的解决方案,但是我还没有遇到任何问题。 gunicorn.service中的执行行如下:

ExecStart=/home/django/.pyenv/versions/django/bin/gunicorn --access-logfile /backup/logs/app_gunicorn_access.log --error-logfile /backup/logs/app_gunicorn_errors.log --workers 3 --timeout=600 --graceful-timeout=10 --log-level=DEBUG --capture-output --bind unix:/www/app/app.sock app.wsgi:application

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM