Make your Nginx RTMP live with the ability to count the number of users watching a channel online

Source: Internet
Author: User
Tags install openssl xsl install perl

Your Nginx already has the RTMP live function, if you also want to count a live channel currently viewing the user volume, you can join the With-http_xslt_module module. The steps are as follows:
1. View the original parameters
/usr/local/nginx/sbin/nginx-v
The output can be obtained from the original compile-time parameters, such as the author obtained:
--user=nginx--group=nginx--with-http_stub_status_module--with-http_gzip_static_module--with-http_ssl_ Module--with-http_flv_module--with-http_perl_module--with-mail
These parameters are still useful when we install the new module.
2. Download the Nginx-rtmp-module installation package
Nginx-rtmp-module-master.zip, Latest: Https://github.com/arut/nginx-rtmp-module.
After downloading, unzip it to get the Nginx-rtmp-module-master directory.
3. Download the nginx-1.3.8.tar.gz package
You can find the version you need in http://nginx.org/download/.
Unzip to get nginx-1.3.8 directory after download.
4. Close Nginx
ps-ef | grep nginx
Find the master process in the list of processes, which is the main process number of nginx.
kill-term main process number
Nginx is closed.
5. Install other dependent packages
Yum Install Pcre-devel
Yum Install Openssl-devel
Yum Install Perl-devel perl-extutils-embed
Yum Install GCC
Yum install libxml2 libxml2-devel libxslt libxslt-devel

6. Compiling the With-http_xslt_module module
Add the following parameters after the series of parameters obtained in step one:
--with-http_xslt_module--add-module=/home/defonds/nginx-rtmp-module-master
Where/home/defonds/nginx-rtmp-module-master is the directory that is obtained by step two.
Switch to step three to get the nginx-1.3.8 directory, using the new combination of the resulting parameter list reconfiguration:
./configure--prefix=/usr/local/nginx--user=nginx--group=nginx--with-http_stub_status_module--with-http_ Gzip_static_module--with-http_ssl_module--with-http_flv_module--with-http_perl_module--with-mail--with-http_ Xslt_module--add-module=/home/defonds/nginx-rtmp-module-master
Then compile:
Make
Finally, replace the original binary execution file:
Cp/usr/local/nginx/sbin/nginx/usr/local/nginx/sbin/nginx.bak
CP./objs/nginx/usr/local/nginx/sbin/

7. Modify Nginx configuration file
Create a simple XLS table file nclients.xsl to extract the number of users viewing the current channel, and edit its contents as follows:
[HTML]View Plain copy print?
  1. < xsl:stylesheet version="1.0 " xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2.   
  3. < xsl:output method="html"/>
  4.   
  5. < xsl:param name="app"/>   
  6. < xsl:param name="name"/>   
  7.   
  8. < xsl:template match="/">   
  9. < xsl:value-of Select="Count (//application[name= $app]/ Live/stream[name= $name]/client[not (Publishing) and Flashver]) "/>
  10. </xsl:template >
  11.   
  12. </xsl:stylesheet >

Then put it in a directory, such as/home/www.
Modify the Nginx Master Profile nginx.conf and add the following:
[HTML]View Plain copy print?
    1. Location/stat {
    2. Rtmp_stat All;
    3. Allow 127.0.0.1;
    4. }  
    5. location/nclients {
    6. Proxy_pass Http://127.0.0.1/stat;
    7. xslt_stylesheet/home/www/nclients.xsl app=' $arg _app ' Name   =' $arg _name ';
    8. add_header Refresh "3;  $request _uri ";
    9. }  

8. Restart Nginx
/usr/local/nginx/sbin/nginx
No news is good news, the terminal has no output to prove the success of the launch. Otherwise, the reference terminal gives the exception information to check the master configuration file.
Access the following address according to the live channel:
HTTP//Live server Ip/nclients?app=app application name &name= channel name
A return result indicates that the With-http_xslt_module module was successfully installed. The return result is the number of viewers of the current channel.

Reference: Nginx RTMP module Nginx-rtmp-module instruction detailed;
Https://github.com/arut/nginx-rtmp-module/wiki/Getting-number-of-subscribers.

Make your Nginx RTMP live with the ability to count the number of users watching a channel online

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.