【问题标题】:Nginx fails randomly on big file uploadNginx 在大文件上传时随机失败
【发布时间】:2016-08-18 01:30:32
【问题描述】:

我有一个存储在 DigitalOcean 的 Rails 应用程序。在大文件上传(~70Mb)期间,我的 Nginx 不时出现故障(可以说是 3 次)。我也有后台导入进程正在运行(但我不确定它是否与问题有关)。

我收到 502 错误,在日志中我看到 upstream permanently closed connection while reading response header from upstream

我的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 一直失败的原因以及如何解决?

【问题讨论】:

  • 错误信息明确指出这是上游问题。您的 Rail 应用会在发送完整响应之前关闭连接。

标签: ruby-on-rails nginx


【解决方案1】:

通常不应在请求期间执行文件上传,因为您无法保证文件将在请求超时之前完成上传。您应该使用Active Job 在后台上传文件,然后在文件上传后提醒用户。

【讨论】:

  • nginx 可以很好地处理上传,在上传完成之前它不会将请求传递给应用程序
猜你喜欢
  • 2012-09-13
  • 2019-01-23
  • 1970-01-01
  • 2012-02-01
  • 2017-11-06
  • 2022-11-24
  • 2021-12-07
  • 2018-12-01
  • 2012-05-31
相关资源
最近更新 更多