Let your Nginx RTMP live broadcast have the function of counting the number of users watching a channel online

If your Nginx already has RTMP live broadcast function, if you want to count the number of users currently watching a live channel, you can add the with-http_xslt_module module. The specific steps are as follows:
        1. View the original parameters
        /usr/local/nginx/sbin/nginx -V
        output to get the parameters that were originally compiled with, for example, the author gets:
        --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 new modules.
        2. Download the nginx-rtmp-module installation package
        nginx-rtmp-module-master.zip, the latest download address: 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  and find the version you need
        at  http://nginx.org/download/ .
        After downloading, unzip it to get the nginx-1.3.8 directory.
        4. Close nginx
        ps - ef | grep nginx
        finds the master process in the process list, which is the master process number of nginx.
        kill -TERM The main process number
        nginx is shut down.
        5. Install other dependencies
        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. Compile the with-http_xslt_module module
        to get it in step 1 Add the following parameters after a series of parameters:
        --with-http_xslt_module --add-module=/home/defonds/nginx-rtmp-module-master
        where /home/defonds/nginx-rtmp-module-master is obtained in step 2 content.
        Switch to the nginx-1.3.8 directory obtained in step 3, and reconfigure using the parameter list obtained by the new combination:
        ./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 executable:
        cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
        cp ./objs/nginx /usr/local/nginx/sbin/
        7. Modify the nginx configuration file
        to create a simple xls table file nclients.xsl for extracting the current channel The number of users, edit its content as follows:

[html]  view plain copy  
 
  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, say /home/www.
        Modify the nginx main configuration file nginx.conf and add the following:

[html]  view plain copy  
 
  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, there is no output from the terminal to prove that the startup was successful. Otherwise, check the main configuration file with reference to the abnormal information given by the terminal.
        Access the following address according to the live channel:
        http://live server IP/nclients?app=app application name&name=channel name
        If the returned result indicates that the with-http_xslt_module module is successfully installed. The returned result is the number of viewers of the current channel.

Reference: Detailed explanation of the nginx-rtmp-module instruction of the Nginx RTMP module ;
https://github.com/arut/nginx-rtmp-module/wiki/Getting-number-of-subscribers .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325756491&siteId=291194637