使用nginx搭建点播和直播流媒体服务器的方法步骤

 更新时间:2018年03月21日 09:07:36   作者:限albert  
本篇文章主要介绍了使用nginx搭建点播和直播流媒体服务器的方法步骤,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

环境   centos7 nginx

1 安装nginx依赖包 yum install gcc gcc-c++ openssl-devel zlib-devel pcre pcre-devel yamdi

2.下载解压nginx_mod_h264_streaming,让nginx支持flv,mp4流播放   wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz 解压后需要修改src目录下的ngx_http
_streaming_module.c文件,将r->zero_in_uri所在的if语句注释掉

3.下载解压nginx-rtmp-module,让nginx支持rtmp/hls协议,wegt -o nginx-rtmp-module.zip  https://github.com/arut/nginx-rtmp-module/archive/master.zip

4下载清除缓存的模块 wget -Ongx_cache_purge.zip     https://github.com/FRiCKLE/ngx_cache_purge/archive/master.zip

5.下载nginx  wget http://nginx.org/download/nginx-1.9.0.tar.gz

6 .进入nginx的安装目录下 执行以下命令./configure --prefix=/usr/local/nginx/--add-module=../nginx-rtmp-module-master --add-module=../ngx_cache_purge-master--add-module=../nginx_mod_h264_streaming-2.2.7 --with-http_stub_status_module--with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module--with-http_flv_module

7. 执行以下命令编译文件make && make install ,并修改nginx安装目录下的objs下的Makefile 删除-Werror

9. 修改nginx.conf

10. 通过yum 停止firewalld防火墙并卸载,然后安装iptables-services修改/etc/sysconfig/iptables文件夹放行80端口

11.nginx 配置如下:

#使用的用户和组
#user nobody;
#指定工作衍生的进程数,为cpu的核心数总和
worker_processes 2;
#指定错误日志的存放路径 日志记录级别[debug,info,notice,warn,error,crit]
error_log  /usr/local/nginx/logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#指定pid存放的路径
pid    /usr/local/nginx/logs/nginx.pid;
events {
  #使用的网络I/O模型,linux系统推荐是epoll而freeBSD是kqueue
  use epoll;
  #允许的连接数,最大的高并发连接数为worker_processes*worker_connections
  worker_connections 51200;
}

rtmp {
 server {
  listen 1935;
  chunk_size 4096;
  application live {
   live on;
   record off;
  }
  #application live2 {
   #live on;
   #record off;
  #}
  # video on demand
  application media {
   play /usr/local/nginx/html/;
  }
  #application vod_http {
   #play http://192.168.31.185/vod;
  #}
  application hls {
   live on;
   hls on;
   hls_path /tmp/hls;
  }
 }
}

http {
  include    mime.types;
  default_type application/octet-stream;
  #
  #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  #         '$status $body_bytes_sent "$http_referer" '
  #         '"$http_user_agent" "$http_x_forwarded_for"';

  #access_log logs/access.log main;
  sendfile    on;
  #tcp_nopush   on;
  #keepalive_timeout 0;
  keepalive_timeout 65;
  gzip on;
  server {
    listen    80;
    server_name localhost;
    #charset koi8-r;
    #access_log logs/host.access.log main;
    location / {
      root  html;
      index index.html index.htm;
    }

location ~ \.flv$ {
  root /usr/local/nginx/html/media/;  
  flv;
}
location ~ \.mp4$ {
  root /usr/local/nginx/html/media/; 
  mp4;
}

location /stat {
   rtmp_stat all;
   # Use this stylesheet to view XML as web page
   # in browser
   rtmp_stat_stylesheet stat.xsl;
 }
 location /stat.xsl {
   # XML stylesheet to view RTMP stats.
   # Copy stat.xsl wherever you want
   # and put the full directory path here
   root /path/to/stat.xsl/;
 }
 location /hls {
   # Serve HLS fragments
   types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
   }
   root /tmp;
   add_header Cache-Control no-cache;
 }
 location /dash {
   # Serve DASH fragments
   root /tmp;
   add_header Cache-Control no-cache;
 }

    #error_page 404       /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
      root  html;
    }


    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #  proxy_pass  http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #  root      html;
    #  fastcgi_pass  127.0.0.1:9000;
    #  fastcgi_index index.php;
    #  fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    #  include    fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #  deny all;
    #}
  }

  # another virtual host using mix of IP-, name-, and port-based configuration
  #
  #server {
  #  listen    8000;
  #  listen    somename:8080;
  #  server_name somename alias another.alias;

  #  location / {
  #    root  html;
  #    index index.html index.htm;
  #  }
  #}

  # HTTPS server
  #
  #server {
  #  listen    443 ssl;
  #  server_name localhost;

  #  ssl_certificate   cert.pem;
  #  ssl_certificate_key cert.key;

  #  ssl_session_cache  shared:SSL:1m;
  #  ssl_session_timeout 5m;

  #  ssl_ciphers HIGH:!aNULL:!MD5;
  #  ssl_prefer_server_ciphers on;

  #  location / {
  #    root  html;
  #    index index.html index.htm;
  #  }
  #}
}

12. 输入xxx.xxx.xxx.xxx/*.mp4/*.flv就能播放视频了

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • Nginx服务器中的location配置详解

    Nginx服务器中的location配置详解

    这篇文章主要介绍了Nginx服务器中的location配置详解,包括location的匹配顺序等基本概念,需要的朋友可以参考下
    2015-08-08
  • 基于nginx反向代理获取用户真实Ip地址详解

    基于nginx反向代理获取用户真实Ip地址详解

    我们访问互联网上的服务时,大多数时客户端并不是直接访问到服务端的,而是客户端首先请求到反向代理,反向代理再转发到服务端实现服务访问,这篇文章主要给大家介绍了关于如何基于nginx反向代理获取用户真实Ip地址的相关资料,需要的朋友可以参考下
    2022-03-03
  • 解读nginx负载均衡的5种策略

    解读nginx负载均衡的5种策略

    这篇文章主要介绍了解读nginx负载均衡的5种策略,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-07-07
  • CentOS 7.3.1611编译安装Nginx1.10.3+MySQL5.7.16+PHP7.1.2

    CentOS 7.3.1611编译安装Nginx1.10.3+MySQL5.7.16+PHP7.1.2

    这篇文章主要介绍了CentOS 7.3.1611编译安装Nginx1.10.3+MySQL5.7.16+PHP7.1.2,需要的朋友可以参考下
    2018-01-01
  • Nginx配置PHP的Yii与CakePHP框架的rewrite规则示例

    Nginx配置PHP的Yii与CakePHP框架的rewrite规则示例

    这篇文章主要介绍了Nginx配置PHP的Yii与CakePHP框架的rewrite规则示例,是这两款高人气框架使用Nginx的关键配置点,需要的朋友可以参考下
    2016-01-01
  • Nginx各个模块的配置及常用配置选项

    Nginx各个模块的配置及常用配置选项

    本文总结了Nginx常用配置选项,包括url匹配优先级、请求转发、日志配置、超时配置、静态文件处理以及负载均衡的各项算法,对Nginx 模块配置相关知识感兴趣的朋友一起看看吧
    2022-01-01
  • nginx配置ssl证书实现https访问的示例

    nginx配置ssl证书实现https访问的示例

    这篇文章主要介绍了nginx配置ssl证书实现https访问的示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-03-03
  • nginx配置多个虚拟主机vhost的方法示例

    nginx配置多个虚拟主机vhost的方法示例

    这篇文章主要介绍了nginx配置多个虚拟主机vhost的方法示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-10-10
  • win10上安装nginx的方法步骤

    win10上安装nginx的方法步骤

    这篇文章主要介绍了win10上安装nginx的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-10-10
  • Nginx启用proxy_cache缓存的方法

    Nginx启用proxy_cache缓存的方法

    本篇文章主要介绍了Nginx启用proxy_cache缓存的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-03-03

最新评论