nginx1.6.0 flv,mov,avi stream media server

本文举个简单的例子, 关于使用nginx搭建流媒体服务.
nginx的安装参考 : 

我们把流媒体文件放到/media目录, 放3个测试文件, 分别包含了avi, flv, mov格式.
另外还需要一个WEB播放器, 使用jwplayer.swf.
[root@dba conf]# cd /media/
[root@dba media]# ll
total 110330
-rw-r--r-- 1 root root 42032120 Dec 22  2013 1.avi
-rw-r--r-- 1 root root 16776688 Oct 30  2013 img_0256.mov
-rw-r--r-- 1 root root 54213271 Oct 30  2013 mayun.flv
-rw-r--r-- 1 root root    91042 Jun  7  2010 player.swf


和flv,mov,avi文件结束相关的location 配置, nginx.conf : 
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;

    server {
        listen       0.0.0.0:80;
        server_name  dba.sky-mobi.com default_server;
        location ~ \.flv$ {
                limit_rate_after 5M;  # 下载5M后开始限速.
                limit_rate 1M;        # 限速1M/s.
                root /media;
                flv;
        }
        location ~ \.swf$|\.mov$|\.avi$ {
                limit_rate_after 5M;
                limit_rate 1M;
                root /media;
        }
    }
}


[root@dba media]# cd /opt/nginx1.6.0/conf/
[root@dba conf]# cat mime.types

types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;

    text/mathml                           mml;
    text/plain                            txt;
    text/vnd.sun.j2me.app-descriptor      jad;
    text/vnd.wap.wml                      wml;
    text/x-component                      htc;

    image/png                             png;
    image/tiff                            tif tiff;
    image/vnd.wap.wbmp                    wbmp;
    image/x-icon                          ico;
    image/x-jng                           jng;
    image/x-ms-bmp                        bmp;
    image/svg+xml                         svg svgz;
    image/webp                            webp;

    application/font-woff                 woff;
    application/java-archive              jar war ear;
    application/json                      json;
    application/mac-binhex40              hqx;
    application/msword                    doc;
    application/pdf                       pdf;
    application/postscript                ps eps ai;
    application/rtf                       rtf;
    application/vnd.apple.mpegurl         m3u8;
    application/vnd.ms-excel              xls;
    application/vnd.ms-fontobject         eot;
    application/vnd.ms-powerpoint         ppt;
    application/vnd.wap.wmlc              wmlc;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/x-7z-compressed           7z;
    application/x-cocoa                   cco;
    application/x-java-archive-diff       jardiff;
    application/x-java-jnlp-file          jnlp;
    application/x-makeself                run;
    application/x-perl                    pl pm;
    application/x-pilot                   prc pdb;
    application/x-rar-compressed          rar;
    application/x-redhat-package-manager  rpm;
    application/x-sea                     sea;
    application/x-shockwave-flash         swf;
    application/x-stuffit                 sit;
    application/x-tcl                     tcl tk;
    application/x-x509-ca-cert            der pem crt;
    application/x-xpinstall               xpi;
    application/xhtml+xml                 xhtml;
    application/xspf+xml                  xspf;
    application/zip                       zip;

    application/octet-stream              bin exe dll;
    application/octet-stream              deb;
    application/octet-stream              dmg;
    application/octet-stream              iso img;
    application/octet-stream              msi msp msm;

    application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet          xlsx;
    application/vnd.openxmlformats-officedocument.presentationml.presentation  pptx;

    audio/midi                            mid midi kar;
    audio/mpeg                            mp3;
    audio/ogg                             ogg;
    audio/x-m4a                           m4a;
    audio/x-realaudio                     ra;

    video/3gpp                            3gpp 3gp;
    video/mp2t                            ts;
    video/mp4                             mp4;
    video/mpeg                            mpeg mpg;
    video/quicktime                       mov;
    video/webm                            webm;
    video/x-flv                           flv;
    video/x-m4v                           m4v;
    video/x-mng                           mng;
    video/x-ms-asf                        asx asf;
    video/x-ms-wmv                        wmv;
    video/x-msvideo                       avi;
}


flv和mov效果比较好, 支持拖动播放. avi需要windows media解码.

输入以下URL, 自动打开flash player, 播放相应的文件 :

http://dba.sky-mobi.com/player.swf?file=mayun.flv
http://dba.sky-mobi.com/player.swf?file=1.avi
http://dba.sky-mobi.com/player.swf?file=img_0256.mov
如果直接输入以下URL的话会变成下载文件.
http://dba.sky-mobi.com/mayun.flv
http://dba.sky-mobi.com/1.avi
http://dba.sky-mobi.com/img_0256.mov

[参考]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值