環境 ubuntu 12.04
搭建視頻服務器,播放flv和MP4文件,webserver用Nginx,編譯增加http_flv_module;播放器使用開源的jw player。
nginx在ubuntu上用apt-get安裝默認編譯選項裏面沒有http_flv_module,所以需要重新編譯一遍,順便升級到了最新的穩定版1.2.7
編譯nginx需要下載openssh包,PCRE包,zlib包
下載相應包文件後
- #增加http_flv_module
- ./configure --with-http_flv_module --prefix=/usr/local/nginx
- make
- sudo make install
不報錯的話 nginx已經編譯完成,編譯後的文件結構如下:
- nginx path prefix: "/usr/local/nginx"
- nginx binary file: "/usr/local/nginx/sbin/nginx"
- nginx configuration prefix: "/usr/local/nginx/conf"
- nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
- nginx pid file: "/usr/local/nginx/logs/nginx.pid"
- nginx error log file: "/usr/local/nginx/logs/error.log"
- nginx http access log file: "/usr/local/nginx/logs/access.log"
- nginx http client request body temporary files: "client_body_temp"
- nginx http proxy temporary files: "proxy_temp"
- nginx http fastcgi temporary files: "fastcgi_temp"
- nginx http uwsgi temporary files: "uwsgi_temp"
- nginx http scgi temporary files: "scgi_temp"
建立軟連接
- sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
輸入 sudo nginx 啓動nginx
修改/usr/local/nginx/conf/nginx.conf
- #在http{}塊內增加
- location ~ \.flv {
- flv;
- }
即可增加對flv模塊的支持,重新啓動nginx
- #重新啓動Nginx
- sudo /usr/sbin/nginx -s reload
- #或者採用
- sudo /usr/sbin/nginx -s stop
- sudo nginx
下載jw player,開源軟件,專業版和高級版需要付費,下載地址
- http://www.longtailvideo.com/jw-player/
將下載的包解壓,見jwplayer文件夾全部上傳到網站根目錄下
在網頁<head>中引用
- <script type="text/javascript" src="/jwplayer/jwplayer.js"></script>
然後增加播放器
- <div id="myElement">Loading the player...</div>
- <script type="text/javascript">
- jwplayer("myElement").setup({
- file: "/uploads/myVideo.mp4",
- p_w_picpath: "/uploads/myPoster.jpg"
- });
- </script>