windows搭建ngnix+rtmp服务实现推/拉流测试

背景:导播app测试,更好的判断出是流媒体源问题还是app端问题

操作:

一.搭建环境

1.下载ngnix

进入ngnix下载页面(http://nginx-win.ecsds.eu/download/ ),选择适合版本下载,本人下载的是nginx 1.7.11.3 Gryphon,解压放在自己想放置的文件夹中

2.下载服务器状态检测程序

下载地址:https://github.com/arut/nginx-rtmp-module/,将文件解压后复制到目录nginx 1.7.11.3 Gryphon下,确保stat.xls文件目录为nginx-1.7.11.3-Gryphon\nginx-rtmp-module\stat.xsl

3.创建配置文件

进入nginx 1.7.11.3 Gryphon\conf目录下方,新建文件nginx-win-rtmp.conf,内容如下:

#user kk;

# multiple workers works !

worker_processes  2;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections  8192;

    # max value 32768, nginx recycling connections+registry optimization =

    #  this.value * 20 = max concurrent connections currently tested with one worker

    #  C1000K should be possible depending there is enough ram/cpu power

    # multi_accept on;

}

rtmp {

    server {

        listen 1935;

        chunk_size 4000;

        application live {

            live on;

            # record first 1K of stream

            # record all;

            # record_path /tmp/av;

            # record_max_size 1K;

            # append current timestamp to each flv

            #record_unique on;

#notify_method get;

#on_publish http://localhost:80/on_publish;

#on_play http://localhost:10078/user/auth;

            #publish only from localhost

            #allow publish 172.30.220.93;

            # deny publish all;

            #allow play all;

        }

    }

}

http {

    #include      /nginx/conf/naxsi_core.rules;

    include      mime.types;

    default_type  application/octet-stream;

    #log_format  main  '$remote_addr:$remote_port - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

#    # loadbalancing PHP

#    upstream myLoadBalancer {

#        server 127.0.0.1:9001 weight=1 fail_timeout=5;

#        server 127.0.0.1:9002 weight=1 fail_timeout=5;

#        server 127.0.0.1:9003 weight=1 fail_timeout=5;

#        server 127.0.0.1:9004 weight=1 fail_timeout=5;

#        server 127.0.0.1:9005 weight=1 fail_timeout=5;

#        server 127.0.0.1:9006 weight=1 fail_timeout=5;

#        server 127.0.0.1:9007 weight=1 fail_timeout=5;

#        server 127.0.0.1:9008 weight=1 fail_timeout=5;

#        server 127.0.0.1:9009 weight=1 fail_timeout=5;

#        server 127.0.0.1:9010 weight=1 fail_timeout=5;

#        least_conn;

#    }

    sendfile        off;

    #tcp_nopush    on;

    server_names_hash_bucket_size 128;

## Start: Timeouts ##

    client_body_timeout  10;

    client_header_timeout 10;

    keepalive_timeout    30;

    send_timeout          10;

    keepalive_requests    10;

## End: Timeouts ##

    #gzip  on;

    server {

        listen      80;

        server_name  localhost;

#location /on_publish{

#default_type text/html;

#set $pass 0;

#if ($query_string ~* "pass=(.+)$"){

#set $pass $1;

#}

#if ($pass = 89437589){

#return 200 pass....$pass;}

#if ($pass != 89437589){

#return 404;}

#}

        location /stat {

            rtmp_stat all;

            rtmp_stat_stylesheet stat.xsl;

        }

        location /stat.xsl {

            root nginx-rtmp-module/;

        }

        location /control {

            rtmp_control all;

        }

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        ## Caching Static Files, put before first location

        #location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {

        #    expires 14d;

        #    add_header Vary Accept-Encoding;

        #}

# For Naxsi remove the single # line for learn mode, or the ## lines for full WAF mode

        location / {

            #include    /nginx/conf/mysite.rules; # see also http block naxsi include line

            ##SecRulesEnabled;

        ##DeniedUrl "/RequestDenied";

        ##CheckRule "$SQL >= 8" BLOCK;

        ##CheckRule "$RFI >= 8" BLOCK;

        ##CheckRule "$TRAVERSAL >= 4" BLOCK;

        ##CheckRule "$XSS >= 8" BLOCK;

            root  html;

            index  index.html index.htm;

        }

# For Naxsi remove the ## lines for full WAF mode, redirect location block used by naxsi

        ##location /RequestDenied {

        ##    return 412;

        ##}

## Lua examples !

#        location /robots.txt {

#          rewrite_by_lua '

#            if ngx.var.http_host ~= "localhost" then

#              return ngx.exec("/robots_disallow.txt");

#            end

#          ';

#        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page  500 502 503 504  /50x.html;

        location = /50x.html {

            root  html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass  http://127.0.0.1;

        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root          html;

        #    fastcgi_pass  127.0.0.1:9000; # single backend process

        #    fastcgi_pass  myLoadBalancer; # or multiple, see example above

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        #    include        fastcgi_params;

        #}

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen      8000;

    #    listen      somename:8080;

    #    server_name  somename  alias  another.alias;

    #    location / {

    #        root  html;

    #        index  index.html index.htm;

    #    }

    #}

    # HTTPS server

    #

    #server {

    #    listen      443 ssl spdy;

    #    server_name  localhost;

    #    ssl                  on;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_prefer_server_ciphers On;

    #    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    #    ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:ECDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!eNULL:!MD5:!DSS:!EXP:!ADH:!LOW:!MEDIUM;

    #    location / {

    #        root  html;

    #        index  index.html index.htm;

    #    }

    #}

}

二.启动服务推流(无权限校验服务,即推/拉流时不需要输入账号和密码)

1.启动ngnix服务

cmd进入到nginx 1.7.11.3 Gryphon目录下方,执行命令:nginx.exe -c conf\nginx-win-rtmp.conf

2.使用ffmpeg进行推流(也可以使用其他工具进行推流)

进入ffmpeg目录下,执行命令:ffmpeg -re -i test.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost:1935/live/t0A(test.mp4为需要推流的本地文件及路径)

3.使用VLC视频播放软件拉流观看

打开VLC,ctrl+n打开媒体,输入推流的地址,点击播放就可以进行观看了


三.ngnix+rtmp服务加入权限验证

1.进入配置文件:nginx 1.7.11.3 Gryphon\conf\nginx-win-rtmp.conf编辑修改文件中rtmp和http配置(主要是利用on_publish跳转到当前配置的一个“location”,在这里进行验证。关键点在于rtmp application节点下面要配置“notify_method get;”为什么呢?因为跳转的时候,默认以POST方式传输参数,修改成GET方式,nginx配置里就可以轻松处理了。)


2.重启ngnix服务

3.验证

进入ffmpeg目录,执行命令:ffmpeg -re -i test.mp4 -vcodec libx264 -acodec aac -f flv "rtmp://172.30.220.93:1935/live/home/test0?user=abc&pass=89437589"(如果不加用户名和密码推流时会报错)

四.nginx+ffmpeg同时推多个流

©著作权归作者所有,转载或内容合作请联系作者
禁止转载,如需转载请通过简信或评论联系作者。
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,607评论 6 507
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,239评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,960评论 0 355
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,750评论 1 294
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,764评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,604评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,347评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,253评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,702评论 1 315
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,893评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,015评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,734评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,352评论 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,934评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,052评论 1 270
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,216评论 3 371
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,969评论 2 355

推荐阅读更多精彩内容