Rails 5.2.1 ActiveStorage file downloads with nginx/puma are truncated












2















My first ActiveStorage project was working fine on development (puma only) but on production (nginx/puma), i have an issue for downloading big files that appear as truncated files.



For instance, an uploaded file sized 24.1 MB gives a 5 MB (truncated) download.



I mostly upload pdf files, uploaded files are complete (checked on server) & the preview works fine.



All environments use the config.active_storage.service = :local



config/storage.yml



local:
service: Disk
root: <%= Rails.root.join("storage") %>


Download url is generated using rails_blob_path(document.doc, disposition: :inline)



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.



/etc/nginx/sites-available/default.conf



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;
}


Rails config/puma.rb



# 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









share|improve this question





























    2















    My first ActiveStorage project was working fine on development (puma only) but on production (nginx/puma), i have an issue for downloading big files that appear as truncated files.



    For instance, an uploaded file sized 24.1 MB gives a 5 MB (truncated) download.



    I mostly upload pdf files, uploaded files are complete (checked on server) & the preview works fine.



    All environments use the config.active_storage.service = :local



    config/storage.yml



    local:
    service: Disk
    root: <%= Rails.root.join("storage") %>


    Download url is generated using rails_blob_path(document.doc, disposition: :inline)



    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.



    /etc/nginx/sites-available/default.conf



    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;
    }


    Rails config/puma.rb



    # 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









    share|improve this question



























      2












      2








      2








      My first ActiveStorage project was working fine on development (puma only) but on production (nginx/puma), i have an issue for downloading big files that appear as truncated files.



      For instance, an uploaded file sized 24.1 MB gives a 5 MB (truncated) download.



      I mostly upload pdf files, uploaded files are complete (checked on server) & the preview works fine.



      All environments use the config.active_storage.service = :local



      config/storage.yml



      local:
      service: Disk
      root: <%= Rails.root.join("storage") %>


      Download url is generated using rails_blob_path(document.doc, disposition: :inline)



      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.



      /etc/nginx/sites-available/default.conf



      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;
      }


      Rails config/puma.rb



      # 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









      share|improve this question
















      My first ActiveStorage project was working fine on development (puma only) but on production (nginx/puma), i have an issue for downloading big files that appear as truncated files.



      For instance, an uploaded file sized 24.1 MB gives a 5 MB (truncated) download.



      I mostly upload pdf files, uploaded files are complete (checked on server) & the preview works fine.



      All environments use the config.active_storage.service = :local



      config/storage.yml



      local:
      service: Disk
      root: <%= Rails.root.join("storage") %>


      Download url is generated using rails_blob_path(document.doc, disposition: :inline)



      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.



      /etc/nginx/sites-available/default.conf



      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;
      }


      Rails config/puma.rb



      # 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






      nginx ruby-on-rails-5 rails-activestorage






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 14:29







      Jean-Baptiste Heren

















      asked Nov 19 '18 at 12:38









      Jean-Baptiste HerenJean-Baptiste Heren

      1869




      1869
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Use proxy_http_version 1.1;



          By default, nginx uses HTTP 1.0 for proxying, which does not support chunked transfer encoding.



          http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version






          share|improve this answer
























          • Thanks @amiuhle, that fixed my issue.

            – Jean-Baptiste Heren
            Nov 21 '18 at 11:02











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374839%2frails-5-2-1-activestorage-file-downloads-with-nginx-puma-are-truncated%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Use proxy_http_version 1.1;



          By default, nginx uses HTTP 1.0 for proxying, which does not support chunked transfer encoding.



          http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version






          share|improve this answer
























          • Thanks @amiuhle, that fixed my issue.

            – Jean-Baptiste Heren
            Nov 21 '18 at 11:02
















          1














          Use proxy_http_version 1.1;



          By default, nginx uses HTTP 1.0 for proxying, which does not support chunked transfer encoding.



          http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version






          share|improve this answer
























          • Thanks @amiuhle, that fixed my issue.

            – Jean-Baptiste Heren
            Nov 21 '18 at 11:02














          1












          1








          1







          Use proxy_http_version 1.1;



          By default, nginx uses HTTP 1.0 for proxying, which does not support chunked transfer encoding.



          http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version






          share|improve this answer













          Use proxy_http_version 1.1;



          By default, nginx uses HTTP 1.0 for proxying, which does not support chunked transfer encoding.



          http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 10:34









          amiuhleamiuhle

          1,8631426




          1,8631426













          • Thanks @amiuhle, that fixed my issue.

            – Jean-Baptiste Heren
            Nov 21 '18 at 11:02



















          • Thanks @amiuhle, that fixed my issue.

            – Jean-Baptiste Heren
            Nov 21 '18 at 11:02

















          Thanks @amiuhle, that fixed my issue.

          – Jean-Baptiste Heren
          Nov 21 '18 at 11:02





          Thanks @amiuhle, that fixed my issue.

          – Jean-Baptiste Heren
          Nov 21 '18 at 11:02


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374839%2frails-5-2-1-activestorage-file-downloads-with-nginx-puma-are-truncated%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents