rtmp與hls流媒體服務器搭建:ubuntu下Nginx搭建初探與rtmp-module的添加

關鍵詞:Nignx(http服務器);rtmp,hls(流媒體服務)javascript

 

前言:感謝開源,感謝戰鬥民族。如今在作流媒體服務的一些工做,流媒體服務器搭建的網上教程多入牛毛,可是細細查看,發現不少同志貼上來的教程都有些許問題,還有一些是爬別人的數據得來的,排版上也有問題,讓新手無所適從。本文也是經過翻看一些優質的博文獲得的這篇分享。如下分享的網址就是引用的博文,安利一下。css

1. http://redstarofsleep.iteye.com/blog/2123752html

2. http://blog.csdn.net/cjsafty/article/details/9108587java

3. http://blog.chinaunix.net/uid-20639775-id-154556.htmlnginx

 

教程:git

    1. 下載nginx, openssl, pcre, zlib到一個目錄下,如(/home/user),用wget命令,具體可查看下面的各類版本。github

nginx-1.8.0.tar.gz openssl-1.0.1i.tar.gz pcre-8.37.tar.gz zlib-1.2.8.tar.gz

      2. tar解壓。服務器

tar -zxvf nginx-1.8.0.tar.gz tar -zxvf openssl-1.0.1i.tar.gz tar -zxvf pcre-8.37.tar.gz tar -zxvf zlib-1.2.8.tar.gz

    3. git下nginx-rtmp-module(https://github.com/arut/nginx-rtmp-module),具體略。app

    4. 進入nginx內,配置好,再make和make install。ide

   (這裏強調一下,/home/user裏的user就是你的用戶名,而後是configure的時候最好加入--with-debug)

./configure --prefix=/usr/local/nginx --with-debug --with-pcre=/home/user/pcre/pcre-8.37 --with-zlib=/home/user/zlib/zlib-1.2.8 --with-openssl=/home/user/openssl/openssl-1.0.1i  --add-module=/home/user/nginx-rtmp-module make make install

    5. 進到(/usr/local/nginx/conf),配置好conf,下面來個簡單完整版的

#user  nobody;
worker_processes  1; #這裏能夠經過加入debug模式來查看error.log,內容更加豐富 error_log  logs/error.log debug; #error_log  logs/error.log  notice; #error_log  logs/error.log  info; #pid        logs/nginx.pid; events {     worker_connections  1024; } -------------------------------------@@@ rtmp {     server {         listen 1935;         application myapp {             live on;         }         application hls {             live on;             hls on;             hls_path /tmp/hls;         }     } } ---------------------------------------@@@ http {     include       mime.types;     default_type  application/octet-stream;     sendfile        on;     keepalive_timeout  65;     server {         listen       80;         server_name  localhost;         --------------------------------------------@@@         location /hls {             types {                 application/vnd.apple.mpegurl m3u8;                 video/mp2t ts;             }             root /tmp;             add_header Cache-Control no-cache;        }        --------------------------------------------@@@         location / {             root   html;             index  index.html index.htm;         } }

    加的部分已經在上面標出來了。

    6. 進入(/usr/local/nginx/sbin)運行

./ngnix

    7. 能夠查看端口占用,80,1935是否是在監聽

netstat -ltn

    8. 更多測試

        1)把rtmp流發給服務器

rtmp://ip/myapp/test

    myapp是ngnix.conf裏application設置的,stream爲test則是自定義的。

        2)接收hls流

http://ip/hls/test.m3u8

    hls是http內的location設置的,訪問的是Linux下的(/tmp/hls),test則是按照上面rtmp的test,若是上面是haha,下面也是haha。

        3)ngnix主頁

http://ip

 

後言:有教程說明在./configure時能夠不須要zlib和pcre,這個我沒有試過,真心不須要這兩個模塊的童鞋們能夠不添加。

相關文章
相關標籤/搜索