因为是编译安装,所以需要系统中装有gcc相关的包。

需要用到的源码包有nginx-1.0.4.tar.gz(http://nginx.org/download/nginx-1.0.4.tar.gz)、pcre-8.12.tar.gz(ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz)、nginx_mod_h264_streaming-2.2.7.tar.gz(http://h264.code-shop.com/trac/wiki/Mod-H264-Streaming-Nginx-Version2)。其中pcre-8.12是与perl兼容的正则表达式库模块,nginx-1.0.4是应用服务器主程序,nginx_mod_h264_streaming-2.2.7是MP4流媒体支持模块。

安装步骤如下:

准备工作:

安装之前首先确认系统中是否已安装gcc、openssl-devel、pcre-devel、zlib-devel

       #yum -y install gcc openssl-devel pcre-devel zlib-devel

 

正式安装开始:

1:解压缩各个压缩包

tar zxvf nginx-1.0.4.tar.gz

tar zxvf nginx_mod_h264_streaming-2.2.7.tar.gz

tar zxvf pcre-8.12.tar.gz

 

2:cd pcre-8.12

./configure

make

make install

 

可能出现错误:

configure: error: You need a C++ compiler for C++ support.

#yum install -y gcc gcc-c++

 

3:cd nginx_mod_h264_streaming-2.2.7

根据实际情况修改Makefile文件中的NGINX项的值。NGINX=$(HOME)/nginx-1.0.4/ 版本的修改,查看$home $pwd路径对不对,不对修改之

NGINX=/usr/local/nginx/

 

4:cd nginx-1.0.4

事先修改一下nginx_mod_h264_streaming-2.2.7/src的源代码:ngx_http_streaming_module.c

注释掉:

  /* TODO: Win32

  if (r->zero_in_uri)

  {

    return NGX_DECLINED;

  }*/

然后进入nginx-1.0.4,再configure。

./configure --sbin-path=/usr/local/sbin --without-http-cache --with-http_stub_status_module --with-http_gzip_static_module --with-http_mp4_module --with-http_flv_module --with-pcre=/usr/local/tools/pcre-8.33 --add-module=/usr/local/tools/nginx_mod_h264_streaming-2.2.7 --with-http_ssl_module

make

make install

(注:我安装时候的./configure --prefix=/home/zq/local/nginx --add-module=../nginx_mod_h264_streaming-2.2.7 --sbin-path=/home/zq/local/nginx/sbin --with-debug

之后make,

会报错【ngx_http_streaming_module.c:158: 错误:‘ngx_http_request_t’ 没有名为 ‘zero_in_uri’ 的成员】之类的错误。这需要修改nginx_mod_h264_streaming-2.2.7的源代码:修改ngx_http_streaming_module.c,注释掉

if (r->zero_in_uri)

  {

    return NGX_DECLINED;

  }

这一段。

之后make clean,之后重新configure,重新make,之后make install。)

 

5:防止nginx报Too many open files异常,修改配置放大打开文件数。

a、查看系统最大可打开文件数:ulimit -a

b、临时修改系统最大可打开文件数:ulimit -n 65535

c、永久方法:修改/etc/security/limits.conf,加上:

* - nofile 65535

* - nproc 65535

d、修改nginx配置文件nginx.conf,加上

worker_rlimit_nofile    65535;

如:

[root@localhost conf]# more nginx.conf 

user  root; //系统用户名

worker_processes  8; //一共几个cpu填几

 

error_log  /usr/local/nginx/logs/error.log warn;

pid        /var/run/nginx.pid;

 

worker_rlimit_nofile 65535;

 

events {

    worker_connections  10240;

}

 

6:之后执行命令nginx,启动nginx服务器。访问http://ip:80出现Welcome to nginx! 时证明nginx安装成功。

 

Nginx安装完成之后安装路径在/usr/local/nginx。打开/usr/local/nginx/conf,修改nginx.conf配置文件,添加MP4支持。在server配置中添加如下配置即可

location ~ \.mp4$ {

mp4;

}

配置示例:

server {

    listen       80;

    server_name  localhost;



    location ^~ /index/ {

      alias /var/www/resource-pa/index/;

      add_header Access-Control-Allow-Origin *;

      add_header Access-Control-Allow-Headers X-Requested-With;

      add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

    }



    location ^~ /video/mp4/ {

        alias /var/www/resourcenew/video/mp4/;

        mp4;

    }



    location ~* \.mp4$ {

        root /var/www/resourcenew;

        mp4;

        mp4_buffer_size     1m;

        mp4_max_buffer_size 5m;

    }

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }

}

 

 

测试的话如下:

基本上已经设置完毕,但是此时我们测试的时候还需要一个支持拖拽播放的flash播放器,开源的JW Player就可以实现这样的功能,我将编译的播放器上传上来,供大家下载:

       下载链接:http://blogimg.chinaunix.net/blog/upfile2/100607142612.rar

       下载播放器后,上传到上面设置的/usr/local/nginx/html/flv_file/目录下,闭关把flv视频文件也放到该目录下!

 

/usr/local/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

killall nginx

 

5)、启动nginx后测试:

       http://192.168.1.105/player.swf?type=http&file=test1.mp4

             说明: #我的ip是192.168.1.105

                       #player.swf是我的JW Player播放器

                       #http是表示居于http分发方式

                       #test1.mp4是我的flv视频文件

 

Logo

更多推荐