使用nginx搭建点播和直播流媒体服务器

2024-06-19 18:18

本文主要是介绍使用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搭建点播和直播流媒体服务器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1075781

相关文章

使用Navicat工具比对两个数据库所有表结构的差异案例详解

《使用Navicat工具比对两个数据库所有表结构的差异案例详解》:本文主要介绍如何使用Navicat工具对比两个数据库test_old和test_new,并生成相应的DDLSQL语句,以便将te... 目录概要案例一、如图两个数据库test_old和test_new进行比较:二、开始比较总结概要公司存在多

JavaWeb-WebSocket浏览器服务器双向通信方式

《JavaWeb-WebSocket浏览器服务器双向通信方式》文章介绍了WebSocket协议的工作原理和应用场景,包括与HTTP的对比,接着,详细介绍了如何在Java中使用WebSocket,包括配... 目录一、概述二、入门2.1 POM依赖2.2 编写配置类2.3 编写WebSocket服务2.4 浏

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加

如何使用Spring boot的@Transactional进行事务管理

《如何使用Springboot的@Transactional进行事务管理》这篇文章介绍了SpringBoot中使用@Transactional注解进行声明式事务管理的详细信息,包括基本用法、核心配置... 目录一、前置条件二、基本用法1. 在方法上添加注解2. 在类上添加注解三、核心配置参数1. 传播行为(

在Java中使用ModelMapper简化Shapefile属性转JavaBean实战过程

《在Java中使用ModelMapper简化Shapefile属性转JavaBean实战过程》本文介绍了在Java中使用ModelMapper库简化Shapefile属性转JavaBean的过程,对比... 目录前言一、原始的处理办法1、使用Set方法来转换2、使用构造方法转换二、基于ModelMapper

c++中std::placeholders的使用方法

《c++中std::placeholders的使用方法》std::placeholders是C++标准库中的一个工具,用于在函数对象绑定时创建占位符,本文就来详细的介绍一下,具有一定的参考价值,感兴... 目录1. 基本概念2. 使用场景3. 示例示例 1:部分参数绑定示例 2:参数重排序4. 注意事项5.

使用C++将处理后的信号保存为PNG和TIFF格式

《使用C++将处理后的信号保存为PNG和TIFF格式》在信号处理领域,我们常常需要将处理结果以图像的形式保存下来,方便后续分析和展示,C++提供了多种库来处理图像数据,本文将介绍如何使用stb_ima... 目录1. PNG格式保存使用stb_imagephp_write库1.1 安装和包含库1.2 代码解

Windows设置nginx启动端口的方法

《Windows设置nginx启动端口的方法》在服务器配置与开发过程中,nginx作为一款高效的HTTP和反向代理服务器,被广泛应用,而在Windows系统中,合理设置nginx的启动端口,是确保其正... 目录一、为什么要设置 nginx 启动端口二、设置步骤三、常见问题及解决一、为什么要设置 nginx

一文教你使用Python实现本地分页

《一文教你使用Python实现本地分页》这篇文章主要为大家详细介绍了Python如何实现本地分页的算法,主要针对二级数据结构,文中的示例代码简洁易懂,有需要的小伙伴可以了解下... 在项目开发的过程中,遇到分页的第一页就展示大量的数据,导致前端列表加载展示的速度慢,所以需要在本地加入分页处理,把所有数据先放

查询SQL Server数据库服务器IP地址的多种有效方法

《查询SQLServer数据库服务器IP地址的多种有效方法》作为数据库管理员或开发人员,了解如何查询SQLServer数据库服务器的IP地址是一项重要技能,本文将介绍几种简单而有效的方法,帮助你轻松... 目录使用T-SQL查询方法1:使用系统函数方法2:使用系统视图使用SQL Server Configu