莫问 发表于 2018-11-15 10:45:46

nginx安装-添加MP4播放模块

  nginx安装很简单,但是有的时候是已经安装的nginx ,升级增加nginx 模块功能。
  最近公司要nginx增加一个可以播放 MP4的模块,安装还算顺利,不说废话上命令。
  1 安装依赖
  yum install -y make zilb-devel openssl-devel pcre-devel libaio libaio-devel
  wget http://nginx.org/download/nginx-1.10.3.tar.gz
  #创建用户和用户组
  groupadd www
  useradd -s /sbin/nologin -M -g www www
  #解压
  tar -zxvf nginx-1.10.3.tar.gz
  #进入nginx安装目录
  cd nginx-1.10.3
  #配置 编译安装
  ./configure --user=www --group=www \
  --prefix=/usr/local/nginx \
  --with-http_stub_status_module \
  --with-http_ssl_module \
  --with-http_gzip_static_module \
  --with-http_gunzip_module \
  --with-file-aio \
  --with-http_flv_module \
  make && make install
  #进入nginx sbin启动
  cd /usr/local/nginx/sbin
  ./nginx
  至此安装完毕
  下面是在原有nginx 基础上 增加MP4播放功能模块
  首先下载 nginx_mod_h264_streaming-2.2.7.tar.gz
  wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
  tar -xvf nginx_mod_h264_streaming-2.2.7.tar.gz
  #重点来了
  vim nginx_mod_h264_streaming-2.2.7
  NGINX=$(HOME)/nginx-1.10.3/   #这里修改自己的nginx版本
  #vim nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c
  以下
  TODO: Win32
  if (r->zero_in_uri)
  {
  return NGX_DECLINED;
  }
  改成
  /*
  TODO: Win32
  if (r->zero_in_uri)
  {
  return NGX_DECLINED;
  }
  */
  #然后再次进入nginx的安装目录
  cd nginx-1.10.3
  ./configure --user=www --group=www
  --add-module=/usr/local/src/nginx_mod_h264_streaming-2.2.7 \
  --prefix=/usr/local/nginx \
  --with-http_mp4_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_ssl_module \
  --with-http_gzip_static_module \
  --with-http_gunzip_module \
  --with-file-aio \
  --with-http_flv_module \
  #注意这里只编译 不安装
  make
  #修改nginx配置文件,强烈建议修改备份,我这里是直接添加nginx Vhost的方式直接在nginx的conf 下的conf.d 下面直接添加下面的server
  server {
  listen 80;
  server_name 你的域名;
  root html;
  index index.html index.htm;
  autoindex on;
  autoindex_exact_size off;
  autoindex_localtime on;
  location ~.(jpg|png|gif)$ {
  root /data/www/oul;
  }
  location ~ .*.mp4$ {
  root /data/www/oul;
  mp4;
  }
  }
  注意下 这个关键步骤
  备份您的
  cd/usr/local/nginx/sbin
  cp nginx nginx.bak
  复制新编译好的nginx执行文件
  cp /root/cd nginx-1.10.3/objs/nginx /usr/local/nginx/sbin/nginx
  找一个MP4视频文件放到nginx网站目录默认是/usr/local/nginx/html 下面
  重启 nginx

  有个坑,注意修改nginx的vhost的根访问文件夹 必须重启 >  另外 nginx如果增加其他功能模块的过程大多这样注意 make 只编译不要执行安装备份还你要修改的文件。

页: [1]
查看完整版本: nginx安装-添加MP4播放模块