【问题标题】:Rails + Nginx + activestorage + directupload with large filesRails + Nginx + activestorage + 大文件直接上传
【发布时间】:2021-02-25 18:22:57
【问题描述】:

我无法上传大于 4.7gb 的文件,大于 4.7gb 的文件失败,找不到 404。 在没有 nginx 的情况下它在开发中工作得很好,所以我认为 nginx 是这里问题的根源。

Nginx 配置:

server {
upstream bench {
     server 127.0.0.1:3001;
}

  server_name servername;
  proxy_http_version 1.1;

  root /path/to/server;
  proxy_max_temp_file_size 10024m;
  client_body_in_file_only   on;
  client_body_buffer_size    1M;
  client_max_body_size 100G;
}

  location / {
    try_files $uri @bench;
  }

  location /cable {
    proxy_http_version 1.1;
    proxy_pass http://bench/cable;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
  }

location @bench {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_pass http://bench;
        proxy_headers_hash_max_size 512;
        proxy_headers_hash_bucket_size 128;
        proxy_buffering off;
        proxy_request_buffering off;
}

  error_page 500 502 503 504 /500.html;
  keepalive_timeout 10;

routes.rb

Rails.application.routes.draw do
  resources :benches, :path => "benchmarks"
  root 'benches#index'
end

【问题讨论】:

  • 请分享rails路线
  • 在编辑中添加了路线

标签: ruby-on-rails nginx rails-activestorage


【解决方案1】:

问题不在于 nginx。开始上传时创建的 service_url activestorage 默认只有 5 分钟有效,所以如果你的文件需要超过 5 分钟才能上传.. 你就不走运了。

config.active_storage.service_urls_expire_in = 1.hour

【讨论】:

    猜你喜欢
    • 2018-08-15
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    • 2018-10-10
    • 2011-09-21
    • 2014-11-13
    • 2019-06-12
    • 2019-04-21
    相关资源
    最近更新 更多