基于Nginx的Rtmp流媒体服务器环境搭建

一、编译安装

wget http://nginx.org/download/nginx-1.4.2.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

安装Nginx需要安装 pcre、openssl库

CentOS:yum install pcre-devel&openssl-devel -y
Ubuntu:sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

tar -zxvf nginx-1.4.2.tar.gz

unzip master.zip

cd nginx-1.4.2

./configure --add-module=../nginx-rtmp-module-master

$ make

$ make install

默认会安装在:/usr/local/nginx/目录下

二、配置

vim /usr/local/nginx/conf/nginx.config
 1 http {

 2     ……

 3 }

 4 在http节点后面加上rtmp配置:

 5 rtmp {

 6     server {

 7         listen 1935;

 8         application live1 {

 9             live on;

10             record off;

11         }

12         application vod {

13             play /var/flv;#视频文件存放路径

14             on_play http://xxxxxx;#播放前调用,返回200则播放继续,3XX则跳转,其他则不播放 ,可以用来做权限校验

15         }

16     }

17 }

三、播放器配置

JwPlayer:

1 <script type='text/javascript'>

2         jwplayer('xxx').setup({

3             streamer: 'rtmp://localhost/vod',#RTMP默认1935端口

4             file: '1.mp4',

5             image: 'view.jpg',

6             width: '100%',

7             aspectratio: '16:9'

8         });

9 </script>

ckplayer:

<script type='text/javascript'>

    var flashvars={

            f:'rtmp://localhost:1935/vod|1.mp4',//流地址与文件名之间用|分割(需要修改配置文件)

            c:0,

            b:0

        };

    var params={bgcolor:'#FFF',allowFullScreen:true,allowScriptAccess:'always'};

    CKobject.embedSWF('/ckplayer/ckplayer.swf','video_flash','ckplayer_a1','609','366',flashvars,params);

</script>

四、启动Nginx

1 $ cd /usr/local/nginx/sbin/

2 $ ./nginx -t    #检查配置文件是否OK

3 #如果nginx还没启动

4 $ ./nginx

5 #如果已经启动了

6 $ ./nginx -s reload  #重新加载配置文件

 

你可能感兴趣的:(nginx)