Nginx – stats for nginx rtmp server

nginxrtmp

I am trying to get stats for nginx as rtmp server, below is my config file, but I'm getting 403 on http://ip:8080/stat.xsl (also tried http://ip/stat.xsl which gives 404 and http://ip:8080/stat/stat.xsl which gives a blank page, no error).

I've copied these settings from here: https://github.com/arut/nginx-rtmp-module

Not sure what is wrong…

I need to find a way to pull stats from the rtmp server or a way of at least getting active connections.

Thanks.

rtmp {
        server {
        listen 1935;
        chunk_size 4000;
        allow play all;

        application live {
                allow play all;
                live on;
                hls on;
                hls_nested on;
                hls_path /HLS/hls;
                hls_fragment 10s;
                record off;
                }
        }
}


http {
        include       mime.types;
        default_type  application/octet-stream;

        server {
                listen 8080;
                location /hls {
                                types {
                                        application/vnd.apple.mpegurl m3u8;
                                }
                alias /HLS/hls;
                add_header Cache-Control no-cache;
                }
                location /stat {
                        rtmp_stat all;
                        rtmp_stat_stylesheet stat.xsl;
                }
                location /stat.xsl {
                root /root/nginx-rtmp-module-dev/stat.xsl/;
                }
        }
}

UPDATE : When I access http://IP:8080/stat/stat.xsl I'm seeing this in Chrome console which I think is related : Resource interpreted as Stylesheet but transferred with MIME type text/xml: http://IP:8080/stat/stat.xsl

Best Answer

I had a similar problem with the RTMP stats.

First, the root location for stat.xsl must be the directory holding stat.xsl. The root location must not be a direct path to stat.xsl. In my case, I placed it in: /var/www/stat.xsl. See location /stat.xsl below:

Secondly, I added 'allow all' to allow anyone to view the stats page. I also added in a refresh header that will cause the stats to update every third second.

This is the contents of my /etc/nginx/sites_available/default file:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    server_name localhost;

    location / {
            try_files $uri $uri/ =404;
            index index.html index.htm index.nginx-debian.html;
    }

    location /stat {
        rtmp_stat all;
        rtmp_stat_stylesheet stat.xsl;
        # Allow access from any visitor
        allow all;
        # Live updates for the stat page
        add_header Refresh "3; $request_uri";
    }

    location /stat.xsl {
        root /var/www/;
    }
}

Then, when you visit http://<hostname>/stat you'll see the RTMP stats presented for each configured stream.