Drupal and Me: Chapter 8 – Large File uploads causing Server connection to Reset

Jul 6th, 2010 | By | Category: Technology

Well this was a jolly good problem that took 4 hours to fix.

I’ve implemented the Audio Module this week to allow our Sound team to upload soundtrack, foley and effects work just the same as the 2D and 3D guys upload their work.  Unfortunately when I went to upload a 40MB .ogg file the connection to the server was reset pretty much exactly after 60 seconds.  So, easy enough I figured I’d just have to go into my php.ini file and change the max upload sizes, max connection times and all of that fun stuff.  Well I went through and changed every conceivable directive in there that had anything to do with connection times and upload sizes.  Nada!  I created .htaccess files in the /drupal dir with php_values to the same effect.. Nada!  I went to one of my wordpress blogs and tried to upload the same file and guess what?  SAme thing happened, re-assuring me that this wasn’t a drupal only problem.  So I tried increasing the Timeout value in apache, nada.  Got onto IRC on #php and no one had a clue.  Hours and hours of googling led to ZERO solutions.  It wasn’t until I decided to try this in Opera instead of Firefox that I was able to get a glimmer of understanding as to what was going on.  Just to once again re-iterate how much better of a browser Opera is than firefox, how exponentially better in every conceivable way except for compatability, Opera is compared to firefox, it took me 30 seconds to figure out and solve this problem once I had opera loading the pages.  Instead of just sending me a nebulous Server Connection Reset error after 60 seconds like FF did, Opera immediately spat out a 413 Error ‘Entity too large’.  Why Firefox didn’t touch on client_max_body_size 300M;

this at all, ever is beyond me but it was a simple matter of going into  my nginx.conf file and “setting client_max_body_size” to 300M and the problem was solved.

Sooo, if you are experiencing a Connection reset error while trying to upload files and you just happen to be running Nginx go and check out your nginx.conf file and make sure client_max_body_size is set nice and high.

Tags: , , , , , , , , , ,

5 Comments to “Drupal and Me: Chapter 8 – Large File uploads causing Server connection to Reset”

  1. krishworks says:

    Thanks, you saved my day!

  2. Vik says:

    Backround of the issue:
    1. When I try to upload a file (file.tar, 23 MB) over http, it takes 3-7 seconds, life is good. This was just for test to make sure backend works!
    2. When I try to upload SAME FILE over https, it goes super slown (20% in 1 minute) and after 60 seconds it dies with a message,
    Timeout sending the file:
    perhaps your browser does not send files correctly,
    your session has expired,
    or there was a server error.
    Please try again.

    Architecture:
    User nginx tomcat

    What backend uploader we are using?
    gwt file uploader

    Environment:
    Centos 6.x (2.6.32-358.11.1.el6.x86_64)

    Tomcat:
    7.x

    What did i try so far in last 48-72 hours ? Why are we certain its nginx configuration issue?
    1. httpd (Apache/2.4.4), another web server works perfect (just for upload) but we dont want to do it for obvious benefits of nginx
    2. if we remove web server altogether, upload works flawlessly.
    3. played with nearly all timeouts on nginx without luck
    4. tried nginx v1.4.1, v1.5.1 without luck (same result)
    5. multiple browsers same result – firefox/chrome windows, firefox/chrome linux
    6. tcpdump and wireshark show data movements for first 60 seconds.
    7. nginx log looks pretty innocent but its not revealing anything meaningful

    Nginx:
    nginx version: nginx/1.5.3
    built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
    TLS SNI support enabled
    configure arguments: –prefix=/apps/nginx –user=nginx –group=nginx –with-file-aio –with-ipv6 –with-http_ssl_module –with-http_realip_module –with-http_addition_module –with-http_xslt_module –with-http_image_filter_module –with-http_geoip_module –with-http_sub_module –with-http_dav_module –with-http_flv_module –with-http_mp4_module –with-http_gzip_static_module –with-http_random_index_module –with-http_secure_link_module –with-http_degradation_module –with-openssl=/apps/nginx153/openssl-1.0.1e –with-pcre=/apps/nginx153/pcre-8.33 –with-http_stub_status_module –with-http_perl_module –with-debug –add-module=/apps/nginx153/ngx_http_log_request_speed

    ————————-nginx.conf, START————————-

    worker_processes 1;

    worker_rlimit_nofile 200000;

    events {
    worker_connections 1024;
    }

    http {
    include mime.types;
    default_type application/octet-stream;

    log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
    ‘$status $body_bytes_sent “$http_referer” ‘
    ‘”$http_user_agent” “$http_x_forwarded_for”‘;
    access_log logs/access.log main;
    error_log logs/error.log;

    sendfile on;
    send_timeout 10;
    keepalive_timeout 30;
    keepalive_requests 100000;
    reset_timedout_connection on;
    client_body_timeout 10;
    client_header_timeout 10;
    gzip on;
    gzip_min_length 10240;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
    gzip_disable “MSIE [1-6]\.”;

    upstream appcluster {
    # least_conn;
    server localhost:8080 fail_timeout=20s;
    keepalive 8;
    }

    server {
    listen 80;
    server_name site.com;
    if ($ssl_protocol = “”) {
    rewrite ^ https://$server_name$request_uri? permanent;
    }
    }

    server {
    listen 443 default ssl;
    root /apps/nginx/html;
    server_name site.com;
    ssl on;
    ssl_certificate /apps/nginx/conf/mycerts/site.crt;
    ssl_certificate_key /apps/nginx/conf/mycerts/site.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass https://appcluster;
    # proxy_pass https://localhost:8080;
    }
    }
    }

    ————————-nginx.conf, END————————-

    Thanks in advance for your suggestions/comments!

  3. Vik says:

    latest nginx.conf has,

    sendfile on;
    send_timeout 360;
    keepalive_timeout 360;
    keepalive_requests 100000;
    reset_timedout_connection on;
    client_body_buffer_size 50M;
    client_body_timeout 360;
    client_header_timeout 360;
    proxy_ignore_client_abort on;
    client_max_body_size 200M;
    gzip on;
    gzip_min_length 10240;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
    gzip_disable “MSIE [1-6]\.”;
    lingering_timeout 360;
    fastcgi_read_timeout 360;

    issue is even if client_max_body_size is 200M, after 60 seconds upload fails 🙁
    this is my 3rd day on it…any comments will be appreciated….

  4. admin says:

    ah I wish I could help you but it’s been so long since I was immersed in drupal.. Hopefully someone else will come along with an answer

  5. vik says:

    no i am not using drupal, am talking about plain file upload

Leave a Comment