http://pengwei.me/nginx-rtmp-secure-your-nginx-server/
网上有解决这个问题的方法,但我在centos 和 windows上都测试了,on_publish 参数确实起了效果,如果验证php页面不通过,确实是能够阻止客户端推流。但是如文中所说,obs客户端推流过来的地址,如:rtmp://x.x.x.x/live/test?user=x&pass=x ,地址参数,这验证页面php是接受不到的 ,所以还是实现不了效果。请问有大大实现了的么,能告知具体方法么?在线等!

解决方案 »

  1.   

    有人做过类似nginx-rtmp的推流权限控制么?
      

  2.   

    网上的都试了,不行,只好自己研究了一天,做了好多次测试,发现了是参数获取问题,不应该使用 _GET获取,正确的是要用 _POST 方式:代码如下:
    在nginx 模块配置文件中设置 on_publish
    nginx.conf
    rtmp {
        server {
            listen 1935;
            ping 30s;
            notify_method get;        application myapp {
                live on;            on_publish http://localhost:8080/on_publish.php;
            }
    }说明: http://localhost:8080/on_publish.php;
    on_publish.php 要放在 能执行 php的地方就行,端口号也不一定是8080,就是你能运行php的网址和端口然后在on_publish.php中做我们的处理。例如:
    on_publish.php<?php// ?user=user&pass=pass@$name = $_POST['name'];
    @$pass = $_POST['pass'];$savename= test;
    $savepass = password;if(empty($name) || empty($pass)){    echo "串码流不正确!";
        header('HTTP/1.0 404 Not Found');}else{
        if (strcmp($name, $savename) == 0 && strcmp($pass, $savepass) == 0) {
            echo "串码流正确!";
        } else {
            echo "串码流不正确!";
            header('HTTP/1.0 404 Not Found');
        }
    }?>
    此代码简单的作了用户验证,也可以改成带数据库验证以及加入更多参数进行验证。
    客服端推流设定
    以Open Broadcaster Software(OBS)为例1、FMS URL:
    rtmp://localhost:1935/myapp2、播放路径/串码流(如果存在):
    test?pass=password其中test为streamkey串码流的名称,?pass=password用来验证的 (实际使用中需要把 test 改为想要的名, password 改成 自己想要的密码,例如设为 1234567890)客户端的 RTMP 设置:rtmp://IP地址:1935/myapp/test本人于2016-10-23 19:00 测试测试成功!
      

  3.   

    nginx-rtmp的推流权限控制,只要控制 推流的名称 和 控制的密匙就行了
    不同的流对应不同的密匙$name 是 nginx-rtmp-module 里的 自带参数名,不要修改
      

  4.   


    大哥,请教nginx.conf应该如何写才好呢,我的是这样的worker_processes  1;#error_log  logs/error.log debug;events {
        worker_connections  1024;
    }rtmp {
        server {
            listen 1935;

            application test_rtmp_1  {live on;}
    application hls {
    live on;
    hls on;  
    hls_path temp/hls;  
    hls_fragment 8s;  
    }
        }
    }http {
        server {
            listen      8087;

            location / {
                root webroot;
            }

            location /stat {
                rtmp_stat all;
                rtmp_stat_stylesheet stat.xsl;
            }        location /stat.xsl {
                root webroot;
            }

    location /hls {  
               #server hls fragments  
    types{  
    application/vnd.apple.mpegurl m3u8;  
    video/mp2t ts;  
    }  
    alias temp/hls;  
    expires -1;  
            }      }
    }
    但是obs推流的时候  URL:rtmp://192.168.1.151/live  
                                         密钥流:test_rtmp_1obs提示:
       请问这样要怎么处理一下,谢谢哈!
      

  5.   

    正解http://blog.csdn.net/wei389083222/article/details/78721074
      

  6.   

    操作系统:windows 2003 server
    web服务器+直播系统:nginx 1.12.1    nginx-rtmp-module 1.2.0
    推流设备:手机客户端,网页推流,obs
    推流地址:rtmp://192.168.1.1:8090/live/test?pass=123
    test为用户名,123为密码
    现在的情况是live/后面不管写什么都可以推出去,虽然也触发了publish.php页面,现在是不管有没有用户都推,也查询了数据库,查询到了用户名该怎么处理,没有查询到该怎么处理,不知道写什么,下边程序有说明
    nginx.conf配置(部分):                listen 1935;
    notify_method POST;
                    application live {

                            live on;
    publish_notify on;
                            #当有设备推流时,触发publish.php
    on_publish 192.168.1.1:8090/publish.php;

            }publish.php文件代码:
    <?php
    @$name=trim($_REQUEST["name"]);
    @$pass=trim($_REQUEST["pass"]);//加了一个写文件操作,是为了验证是否触发了publish.php这个文件,经验证确实触发了。
    $myfile = fopen("testfile.txt", "w");
    //如果都不是空值执行数据库查询
    if(!empty($name) and !empty($pass))
    {
    require "function_php/function.php";
    conn();//调取连接数据库函数
    //查询数据库中是否存在此用户
    $sql="select * from  tbl_user where user_name='$name' and user_pass='$pass'";
    $query=$conn->query($sql);
    $row=$query->num_rows;if ($row ==1 )
    {
    //如果有用户存在把用户名、密码写到文件里,也确实写了。现在的问题是验证正确以后,不知道怎么写,如何告诉nginx.conf文件
    fwrite($myfile,$name."\n");
    fwrite($myfile,$pass."\n");
    fwrite($myfile,$row."\n");

    }
    else
    {
    //如果用户不存在也把用户名和密码写到文件里 验证不正确该怎么写呢?如何停止推流
    fwrite($myfile,$name."\n");
    fwrite($myfile,$pass."\n");
    fwrite($myfile,$row."\n"); }

    $query->free_result();
    $conn->close();
    }
    else
    {
    header('HTTP/1.0 404 Not Found');
    }
    fclose($myfile);
    ?>
      

  7.   

    http_response_code(404);