我有一个存储在 DigitalOcean 的 Rails 应用程序。在大文件上传 (~70Mb) 期间,我的 Nginx 有时会失败(比如每 3 次失败一次)。我还有后台导入进程在运行(但我不确定它是否与问题有关)。
我收到 502 错误,在日志中我看到 在从上游读取响应 header 时上游永久关闭连接
。
我的 nginx.conf
看起来与此类似:
upstream backend {
server unix://var/www/my_app/shared/tmp/sockets/puma.sock;
}
server {
listen 80;
root /var/www/my_app/current/public;
client_max_body_size 600m;
proxy_connect_timeout 1200s;
proxy_send_timeout 1200s;
proxy_read_timeout 1200s;
client_header_timeout 1200s;
client_body_timeout 1200s;
client_header_buffer_size 1024k;
client_body_buffer_size 600m;
send_timeout 1200s;
keepalive_timeout 1200s;
large_client_header_buffers 8 1024k;
fastcgi_read_timeout 1200s;
error_log /var/www/my_app/current/log/nginx.error.log info;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 1200s;
types_hash_max_size 2048k;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
谁能建议 Nginx 一直失败的原因是什么以及如何修复它?
最佳答案
通常不应在请求期间执行文件上传,因为您永远无法保证文件会在请求超时之前完成上传。你应该使用 Active Job在后台上传文件,然后在文件上传后提醒用户。
关于ruby-on-rails - Nginx 在大文件上传时随机失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39002253/