天天看点

Nginx整合mp4,flv模块

注:

nginx 1.1.3之后已经默认支持mp4,flv模块,无须第三方模块支持。

操作步骤:

1:解压,编译nginx,编译添加mp4,flv模块:

1

2

3

4

5

<code># tar -zxvf nginx-1.3.14.tar.gz</code>

<code># cd nginx-1.3.14</code>

<code># ./configure </code>

<code># ./configure --prefix=/usr/local/nginx --user=nobody --group=nobody --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_sub_module --with-http_stub_status_module --with-http_perl_module --with-http_mp4_module --with-http_flv_module</code>

<code># make&amp;&amp; make install</code>

2:配置nginx.conf文件:(server选项配置)

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

<code># limit_conn_zone $binary_remote_addr zone=perip:10m;</code>

<code>server {</code>

<code>    </code><code>listen 80 ;</code>

<code>    </code><code>server_name 117.27.135.82;</code>

<code>    </code><code>root  </code><code>/usr/local/nginx/html/mp4_file/</code><code>;    ----------根路径</code>

<code>    </code><code>limit_rate 256k;</code>

<code> </code> 

<code>    </code><code>location ~ \.flv$                      ---------匹配flv文件</code>

<code>     </code><code>{</code>

<code>         </code><code>flv;</code>

<code>     </code><code>}</code>

<code>    </code><code>location ~ \.mp4$                    ----------匹配mp4文件</code>

<code>     </code><code>mp4;</code>

<code>#    mp4_buffer_size     1m;        </code>

<code>#    mp4_max_buffer_size   5m;</code>

<code>     </code><code>limit_rate_after 5m;                ---------下载5m后再限速</code>

<code>     </code><code>limit_rate 100k;                    ----------限速100k</code>

<code>#    limit_conn perip 1;</code>

3:下载JWplayer,实现视频可拖拽功能。解压,并把player.swf文件放到视频文件目录下。

播放测试:

 在根目录下放入mp4文件VGA.mp4。在浏览器上播放视频。

 地址:http://xx.xx.xx.xx/player.swf?type=http&amp;file=VGA.mp4  (player.swf为播放器,VGA.mp4为要播放的视频文件)

 能正常播放,说明配置成功,如下图:

<a href="http://s3.51cto.com/wyfs02/M00/83/B9/wKioL1d7U0mCRqpfAAIFKMy-FmM756.png" target="_blank"></a>

本文转自 icenycmh 51CTO博客,原文链接:http://blog.51cto.com/icenycmh/1795934,如需转载请自行联系原作者

继续阅读