Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am having a issue with NGINX. I will be serving files to multiple (~4000) people and they might be downloading multiple files at the same time. I have setup nignx and tryed to download a test file (centos dvd 1 4GB) once I try to download the same file multiple times at the the same time it only allows me to download one first and then others sit and wait for me to finish the first download. How can I serve it without any waiting time.

NGINX.conf:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 200000;

events {
    worker_connections  10000;

    multi_accept on;
    use epoll;
}


http {
    include   /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_requests 1000;
    open_file_cache max=1000;

    # Added on 26.07.2013 to make files fly!
    tcp_nopush     on;
    client_max_body_size 5G;
    client_body_timeout 120;
    client_header_timeout 120;
    client_body_buffer_size  128K;
    client_header_buffer_size 1k;
    large_client_header_buffers 4 8k;
    send_timeout 60;
    reset_timedout_connection on;
    types_hash_max_size 2048;
    server_tokens off;
    gzip on;
    gzip_static on;
    gzip_min_length 512;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

VIRTUAL SERVER CONF:

server {

    listen 80;

    server_name *.*.*.*;

    root /usr/share/nginx/html;

    error_log /var/log/nginx/deadz/error.log;
    access_log /var/log/nginx/deadz/access.log;

    index index.html index.htm index.php;
}

How could I optimize it to serve the same file multiple times to one connection.

If you need more information please ask me.

share|improve this question
    
Did you try downloading several times at the same time with the same web browser? –  Michael Hampton Jul 26 '13 at 6:16
    
Yes. It does start the download at first request other requests just sit and wait until first one is completed and so on. I can not download the same file 6x at once. –  mYzk Jul 26 '13 at 6:31
    
Sounds like your web browser is the problem. Try again making simultaneous downloads from different machines. –  Michael Hampton Jul 26 '13 at 6:32
    
Tryed multiple computers and multiple browsers in one computer. Firefox lets me download the file 6x simultaneously and other computers are facing the same problem. Chrome allows me to download the file only 1x simultaneously. Looks like its blocking multiple connections from the same IP –  mYzk Jul 26 '13 at 6:46
    
Try increasing worker_processes. –  Flup Jul 26 '13 at 7:18

1 Answer 1

up vote 0 down vote accepted

Server conf:

 server {

    listen 80;

    server_name *.*.*.*;

    root /usr/share/nginx/html;

    error_log /var/log/nginx/deadz/error.log;
    access_log /var/log/nginx/deadz/access.log;

    index index.html index.htm index.php;

    server_tokens off;

    client_max_body_size 700m;
    connection_pool_size 256;
    client_body_buffer_size 1024k;
    client_header_buffer_size 8k;


    limit_rate 125k;
    limit_req zone=one burst=5;

 }

NGINX conf:

user  nginx;
worker_processes  4;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 20240;

events {
    worker_connections  4000;

    multi_accept on;
    use epoll;
}

http {
    include   /etc/nginx/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  off;

    limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;

    server_tokens off;

    client_header_timeout 10m;
    client_body_timeout 10m;
    send_timeout 10m;

    client_max_body_size 700m;
    connection_pool_size 256;
    client_body_buffer_size 1024k;
    client_header_buffer_size 8k;

    keepalive_timeout 30;
    keepalive_requests 100000;
    reset_timedout_connection on;
    open_file_cache max=200000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;

    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]\.";

    include /etc/nginx/conf.d/*.conf;
}

This fixed my problem :) Now I need to setup HAProxy to balance the downloads.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.