我一直在这个错误上停留一个星期。我正式对此感到茫然。
我有一个React / Django网络应用程序,用户可以在其中上传音频文件(.WAV)(通过react Dropzone)。 React和Django完全分离为frontend /和backend /文件夹,通过fetch()调用进行通信。出于某种原因,我能够上传小于100 MB的文件,但是如果上传的文件较大,例如180 MB,则Nginx错误,并显示以下内容:
2020/07/14 02:29:18 [error] 21023#21023: *71 upstream prematurely closed connection while reading response header from upstream, client: 50.***.***.***, server: api.example.com, request: "POST /api/upload_audio HTTP/1.1", upstream: "http://unix:/home/exampleuser/AudioUploadApp/AudioUploadApp.sock:/api/upload_audio", host: "api.example.com”, referrer: "https://example.com/profile/audio/record"
我的Gunicorn错误日志未显示任何错误。我可以看到5个工作进程中的每一个都开始了,但是没有WORKER TIMEOUT错误或我可以看到的任何东西。
我的guniocorn.service文件:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=exampleuser
Group=www-data
WorkingDirectory=/home/exampleuser/AudioUploadApp/Backend
ExecStart=/home/exampleuser/virtualenvs/uploadenv/bin/gunicorn --access-logfile "/tmp/gunicorn_access.log" --error-logfile "/tmp/gunicorn_error.log" --capture-output --workers 5 --worker-class=gevent --timeout=900 --bind unix/home/exampleuser/AudioUploadApp/AudioUploadApp.sock AudioUploadApp.wsgi:application --log-level=error
[Install]
WantedBy=multi-user.target
server {
server_name api.example.com;
location / {
include proxy_params;
proxy_pass http://unix:/home/exampleuser/AudioUploadApp/AudioUploadApp.sock;
client_max_body_size 200M;
}
location /static {
autoindex on;
alias /home/exampleuser/AudioUploadApp/Backend/static/;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
client_max_body_size 200M;
}
server {
server_name www.example.com example.com;
root /home/exampleuser/AudioUploadApp/build;
index index.html index.html;
location / {
try_files $uri /index.html;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
client_max_body_size 200M;
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name www.example.com example.com;
listen 80;
return 404; # managed by Certbot
}server {
if ($host = api.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name api.example.com;
client_max_body_size 200M;
return 404; # managed by Certbot
}
还有我的Nginx代理参数:
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 900s;
proxy_send_timeout 900s;
proxy_read_timeout 900s;
我意识到我对Gunicorn和Nginx的超时太多了,但是我住的地方没有最好的上载速度,所以我只想确保由于上载速度引起的超时不是问题。 / p>
这是我尝试过的,没有运气:
重申一下,这似乎仅在wav文件大小大于100 MB时发生。我已经成功上传了80 MB的文件,但无法上传150 MB的文件。
我已经做了大约一个星期了。我很困。非常感谢您的帮助。如果错过任何有用的信息,我可以提供更多信息
答案 0 :(得分:0)
此问题的解决方法是升级运行Gunicorn / Django / Nginx的EC2实例。我从t2.medium实例转到R5.large实例。这工作了。然后,我从R5.large降到了t2.large实例,它仍然有效。 t2.medium和t2.large具有相同数量的虚拟CPU,但是t2large具有两倍的内存(4 GiB和8 GiB)。我声称已经做到了,但是当我遇到的第一个错误是关于客户端主体太大时,我一定已经尝试过了。我通过更改Nginx中的client_max_body_size修复了该错误。在进行此更改之后,我收到了该帖子即将涉及的错误。我只是尝试在错误的位置升级硬件。
与原始帖子中的内容相比,我还进行了以下更改,因为似乎不需要更大的数字:
Gunicorn和Nginx可能会降至默认值,但我尚未对此进行测试。我住的地方上传速度很差。