Nginx 學習筆記(三)Nginx + flv

 環境 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包

下載相應包文件後

 

  1. #增加http_flv_module 
  2. ./configure --with-http_flv_module --prefix=/usr/local/nginx 
  3. make 
  4. sudo make install 

不報錯的話 nginx已經編譯完成,編譯後的文件結構如下:

 

  1. nginx path prefix: "/usr/local/nginx" 
  2.  
  3. nginx binary file: "/usr/local/nginx/sbin/nginx" 
  4.  
  5. nginx configuration prefix: "/usr/local/nginx/conf" 
  6.  
  7. nginx configuration file: "/usr/local/nginx/conf/nginx.conf" 
  8.  
  9. nginx pid file: "/usr/local/nginx/logs/nginx.pid" 
  10.  
  11. nginx error log file: "/usr/local/nginx/logs/error.log" 
  12.  
  13. nginx http access log file: "/usr/local/nginx/logs/access.log" 
  14.  
  15. nginx http client request body temporary files: "client_body_temp" 
  16.  
  17. nginx http proxy temporary files: "proxy_temp" 
  18.  
  19. nginx http fastcgi temporary files: "fastcgi_temp" 
  20.  
  21. nginx http uwsgi temporary files: "uwsgi_temp" 
  22.  
  23. nginx http scgi temporary files: "scgi_temp" 

建立軟連接

 

  1. sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx 

輸入 sudo nginx 啓動nginx

修改/usr/local/nginx/conf/nginx.conf

 

  1. #在http{}塊內增加 
  2. location ~ \.flv { 
  3.                 flv; 
  4.         } 

即可增加對flv模塊的支持,重新啓動nginx

 

  1. #重新啓動Nginx 
  2. sudo /usr/sbin/nginx -s reload 
  3. #或者採用 
  4. sudo /usr/sbin/nginx -s stop 
  5. sudo nginx 

下載jw player,開源軟件,專業版和高級版需要付費,下載地址

  1. http://www.longtailvideo.com/jw-player/ 

將下載的包解壓,見jwplayer文件夾全部上傳到網站根目錄下

在網頁<head>中引用

  1. <script type="text/javascript" src="/jwplayer/jwplayer.js"></script> 

然後增加播放器

  1. <div id="myElement">Loading the player...</div> 
  2.  
  3. <script type="text/javascript"> 
  4.     jwplayer("myElement").setup({ 
  5.         file: "/uploads/myVideo.mp4", 
  6.         p_w_picpath: "/uploads/myPoster.jpg" 
  7.     }); 
  8. </script> 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章