Rails 5.2.1 ActiveStorage file downloads with nginx/puma are truncated
up vote
2
down vote
favorite
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
add a comment |
up vote
2
down vote
favorite
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
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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
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
nginx ruby-on-rails-5 rails-activestorage
edited Nov 19 at 14:29
asked Nov 19 at 12:38
Jean-Baptiste Heren
1869
1869
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
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
Thanks @amiuhle, that fixed my issue.
– Jean-Baptiste Heren
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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
Thanks @amiuhle, that fixed my issue.
– Jean-Baptiste Heren
2 days ago
add a comment |
up vote
1
down vote
accepted
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
Thanks @amiuhle, that fixed my issue.
– Jean-Baptiste Heren
2 days ago
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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
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
answered 2 days ago
amiuhle
1,8231326
1,8231326
Thanks @amiuhle, that fixed my issue.
– Jean-Baptiste Heren
2 days ago
add a comment |
Thanks @amiuhle, that fixed my issue.
– Jean-Baptiste Heren
2 days ago
Thanks @amiuhle, that fixed my issue.
– Jean-Baptiste Heren
2 days ago
Thanks @amiuhle, that fixed my issue.
– Jean-Baptiste Heren
2 days ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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