server icon indicating copy to clipboard operation
server copied to clipboard

Downloading big files stalls when using http/2 - Nginx configuration wrong ?

Open derkostka opened this issue 9 years ago • 11 comments

Steps to reproduce

  1. Enable http2 in configuration of nginx
  2. Download a file of medium to big file size (i tested 1,3 GB)
  3. Watch the transfer rate, it drops after the first "chunks", then timeouts

Expected behaviour

Download should complete

Actual behaviour

Transfer rate drops after some seconds, reaches 0, timeouts. If you disable http2 -> no problems

Server configuration

Operating system: Ubuntu 16.04

Web server: nginx/1.10.3, 32 Bit Database: mysql PHP version: 7.1, 32 Bit Nextcloud version: (see Nextcloud admin page) Daily, also happens on NC12 Updated from an older Nextcloud/ownCloud or fresh install: Updated from NC12 Where did you install Nextcloud from: Download, Daily

Nextcloud configuration:

Are you using external storage, if yes which one: local

Are you using encryption: no

Client configuration

**Browser: Chrome 61, 64 Bit

Operating system: OSX 10.12.6

Logs

Web server error log

no entries !

Nextcloud log (data/nextcloud.log)

no entries !

NGINX Configuration

NGINX Config

upstream php-handler { server 127.0.0.1:9000; }

server { listen 4430 ssl http2 default_server; listen [::]:4430 ssl http2 default_server;

access_log /var/log/nginx/access_nc_prod.log;
error_log /var/log/nginx/error_nc_prod.log;

server_name cloud.sebastiankostka.de;    

ssl_certificate /etc/letsencrypt/live/cloud.sebastiankostka.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/cloud.sebastiankostka.de/privkey.pem;

ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;

## modern configuration. tweak to your needs.
ssl_protocols TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;

## HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
add_header Strict-Transport-Security max-age=15768000;

# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this
# topic first.
add_header Strict-Transport-Security "max-age=15768000;
includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
access_log off;
# Path to the root of your installation
root /var/www/nextcloud/;

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
# last;

location = /.well-known/carddav {
  return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
  return 301 $scheme://$host/remote.php/dav;
}

# set max upload size
client_max_body_size 2048M;
fastcgi_buffers 64 4K;

# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;

error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;

location / {
    rewrite ^ /index.php$uri;
}

location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
    deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
    deny all;
}

location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param HTTPS on;

    #Avoid sending the security headers twice
    fastcgi_param modHeadersAvailable true;
    fastcgi_param front_controller_active true;
    fastcgi_pass php-handler;
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
}

location ~ ^/(?:updater|ocs-provider)(?:$|/) {
    try_files $uri/ =404;
    index index.php;
}

# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* \.(?:css|js|woff|svg|gif)$ {
    try_files $uri /index.php$uri$is_args$args;
    add_header Cache-Control "public, max-age=15778463";
    # Add headers to serve security related headers (It is intended to
    # have those duplicated to the ones above)
    # Before enabling Strict-Transport-Security headers please read into
    # this topic first.
    # add_header Strict-Transport-Security "max-age=15768000;
    #  includeSubDomains; preload;";
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;
    # Optional: Don't log access to assets
    access_log off;
}

location ~* \.(?:png|html|ttf|ico|jpg|jpeg)$ {
    try_files $uri /index.php$uri$is_args$args;
    # Optional: Don't log access to other assets
    access_log off;
}

}

derkostka avatar Sep 17 '17 09:09 derkostka

Please review the attached configuration of nginx. I hope that it is only some issue there. (newer) Apache2 works flawless with http2. No error logs in nginx, php or nextcloud logs, so i did not attach theme here.

derkostka avatar Sep 17 '17 09:09 derkostka

Add fastcgi_read_timeout 7200; right below fastcgi_buffers 64 4K;. Restart nginx. Test and tell us.

cluxter avatar Sep 19 '17 16:09 cluxter

Okay, this delays the Problem, from my 1,3 GB file, 135 MB are downloaded, then it stalls again.

derkostka avatar Sep 19 '17 19:09 derkostka

After how long precisely? Could you time it?

cluxter avatar Sep 19 '17 22:09 cluxter

I'm seeing the same drops in download speed, but my file doesn't actually fail to download. it goes to 0 speed, then within 10 seconds or so, starts downloading again. This can repeat multiple times in a large file download. Is there anything I can provide to figure out what may be causing these stalls?

I'm running a nextcloud container that bundles in nginx

Quiksmage avatar Oct 17 '17 06:10 Quiksmage

As there was no feedback on the exact timing and also the exact Nginx config is missing, I would ask you to check your config against the one in our documentation. This works fine for me even for big files and also uses php-fpm.

https://docs.nextcloud.com/server/12/admin_manual/installation/nginx.html

Thanks

MorrisJobke avatar Jan 02 '18 22:01 MorrisJobke

Same problem here and additionally the downloaded file is corrupted. I tried a 11.8 GB folder which downloads to a 1.08 GB tar on a Mac in Chrome that is not extractable. The download hangs at sometimes at 7.8 MB, sometimes at 23 MB then continues after a while, the first 100 MB are quite slow, but then it rushes to the 1 GB.

@MorrisJobke How can I provide you with metrics about the problem? Unfortunately, I have no direct access to the nginx configuration files, but I can find out specific configuration values, if needed.

te-online avatar Jan 15 '18 10:01 te-online

Check the Nginx config against the one in the docs first to be sure, that it is the same.

MorrisJobke avatar Jan 15 '18 10:01 MorrisJobke

@MorrisJobke Thank you, will do. I will try to get these changes https://docs.nextcloud.com/server/11/admin_manual/configuration_files/big_file_upload_configuration.html?highlight=big%20file%20upload implemented first. Because nginx is only a proxy for a correctly configured apache.

te-online avatar Jan 16 '18 11:01 te-online

@Quiksmage I have this exact issue. Did you fix it ?

ghost avatar Jan 25 '18 20:01 ghost

@ArnaudE Yes, but I have no idea what fixed it. I tried so many things.

This is what my nginx config looks like that points to my nextcloud container running on nginx.


server {
	listen 443 ssl;
	server_name domain.com;

	root /config/www;
	index index.html index.htm index.php;

#SSL Certificates
	ssl_certificate /config/keys/letsencrypt/fullchain.pem;
	ssl_certificate_key /config/keys/letsencrypt/privkey.pem;

#Diffie-Hellman key exchange
	ssl_dhparam /config/nginx/dhparams.pem;

#SSL Ciphers
	ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';


#Extra Settings
	ssl_prefer_server_ciphers on;
	ssl_session_cache shared:SSL:10m;

#Add HTTP Strict Transport Security
	add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
	add_header Front-End-Https on;

	client_max_body_size 0;

	location / {
		proxy_pass https://192.168.1.243:6111/;
		proxy_max_temp_file_size 16400M;
		proxy_buffering off;
		proxy_request_buffering off;
		proxy_redirect off;
		proxy_ssl_session_reuse off;
		proxy_http_version 1.1;
		proxy_read_timeout 36000s;
		proxy_pass_header Authorization;
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Connection "";

That's from the config of my letsencrypt container.

Quiksmage avatar Jan 25 '18 22:01 Quiksmage