NGINX configuration for video streaming server

nginxphp-fpmvideo streaming

I have purchased cloud server at digitalocean.com with 2GB RAM and DUAL CORE Processor. I want to set-up video proxy service i.e. to proxy youtube videos.

I have installed NGINX + PHP-FPM server and UFW firewall. But when more than 10 to 20 users stream, site slows down or becomes entirely unreachable.

Following are the configurations:

(NGINX CONFIGURATION)

user www-data;
worker_processes 2;
pid /var/run/nginx.pid;

events {
    worker_connections 19000;
    multi_accept on;
}

worker_rlimit_nofile 20000;
http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log off;
    error_log /var/log/nginx/error.log crit;

    ##
    # Gzip Settings
    gzip on;
    gzip_disable "msie6";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

( PHP-FPM CONFIGURATION )

pm = static
pmm.max_children=1000
pm.process_idle_timeout = 10s

I also tried dynamic and ondemand configurations but no improvement.

pm = dynamic
pm.max_children = 1000
pm.start_servers=2
pm.min_spare_servers = 2
pm.max_spare_servers = 6

Please help in configuring this server.

Best Answer

How do you do the actual proxying?

The details you have provided don't appear sufficient to determine what the bottleneck is. You have not provided anything in regards to what, how and who does the proxying, which is what the root issue resolves around.

My hypothesis is that your proxying app saves the videos to disc, and you might as well be exhausting all of your disc IO allocation. The whole server being unresponsive is a good sign of disc IO exhaustion.

Although nginx is a great tool that I highly recommend, for your specific use-case, you might be better served by varnish. I'd suggest to write the whole proxying logic in varnish; varnish cache will make the most effective use of your 2GB of RAM.