title: Rails 5.2.1 ActiveStorage file downloads with nginx/puma are truncated
body: <p>My first <strong>ActiveStorage</strong> project was working fine on development (puma only) but on production (nginx/puma), i have an issue for downloading big files that appear as <strong>truncated files</strong>.</p>
  
  <p>For instance, an uploaded file sized 24.1 MB gives a 5 MB (truncated) download.</p>
  
  <p>I mostly upload pdf files, uploaded files are complete (checked on server) &amp; the preview works fine.</p>
  
  <p>All environments use the <code>config.active_storage.service = :local</code></p>
  
  <h1>config/storage.yml</h1>
  
  <pre><code>local:
    service: Disk
    root: &lt;%= Rails.root.join("storage") %&gt;
  </code></pre>
  
  <p>Download url is generated using <code>rails_blob_path(document.doc, disposition: :inline)</code></p>
  
  <p>I suspect an option or parameter in puma or nginx that makes downloading the full files fail. As of now I cannot see any error in logs.</p>
  
  <h1>/etc/nginx/sites-available/default.conf</h1>
  
  <pre><code>upstream app {
      # Path to Puma SOCK file, as defined previously
      server unix:/home/deploy/rails/shared/sockets/puma.sock fail_timeout=0;
  }
  
  server {
          listen 80;
  
          root /home/deploy/rails/public;
  
          try_files $uri/index.html $uri @app;
  
          # Make site accessible from http://localhost/
          server_name localhost;
  
          location @app {
              proxy_pass http://app;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header Host $http_host;
              proxy_redirect off;
          }
  
          error_page 500 502 503 504 /500.html;
          keepalive_timeout 10;
          client_max_body_size 4G;
  }
  </code></pre>
  
  <h1>Rails config/puma.rb</h1>
  
  <pre><code># Default to production
  rails_env = ENV['RAILS_ENV'] || "production"
  environment rails_env
  # Change to match your CPU core count
  if rails_env == 'production'
    workers 2
  else
    workers 1
  end
  
  # Min and Max threads per worker
  threads 1, 6
  
  app_dir = File.expand_path("../..", __FILE__)
  shared_dir = "#{app_dir}/shared"
  
  if rails_env == 'production'
    # Set up socket location
    bind "unix://#{shared_dir}/sockets/puma.sock"
  
    # Logging
    stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true
  
    # Set master PID and state locations
    pidfile "#{shared_dir}/pids/puma.pid"
    state_path "#{shared_dir}/pids/puma.state"
    activate_control_app
  
    on_worker_boot do
      require "active_record"
      ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
      ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
    end
  end
  </code></pre>