Nginx with health check modules

We use nginx with a very popular module nginx-rtmp for live stream purpose. When one server is not enough we add a SLB before all these nginx server.

Typically we use Aliyun's SLB instance, and use level 4(TCP) load balancing. But there is one limitation for Aliyun SLB is that the maximum session time is 3600s(1 hour). If you publish one stream via the SLB for over one hour, and the connection disconnects, you retry, you will probably get a new backend server.

For simple RTMP stream it is no problem, but if you want to record all the files, it is impossible to merge all the files together.

So after some search one github, I found two modules which are very usefull to resolve this problems. We replace SLB with nginx servers, using TCP stream with health check, and use consistent algorithm.

Another is also health check module but for HTTP.

Below is simple step for build the module with nginx source.

./configure --prefix=/opt/nginx \
            --with-select_module \
            --with-poll_module \
            --with-http_ssl_module \
            --with-http_realip_module \
            --with-http_xslt_module \
            --with-http_sub_module \
            --with-http_dav_module \
            --with-http_flv_module \
            --with-http_gzip_static_module \
            --with-http_stub_status_module \
            --with-stream \
            --with-debug \
            --add-module=../nginx-rtmp-module-1.2.1 \
            --add-module=../nginx_upstream_check_module \
            --add-module=../ngx_stream_upstream_check_module

Nginx RTMP Module

Stream Upstream Check Module

HTTP Upstream Check

#nginx #slb #upstream