一.开发环境

  Nginx地址:  http://nginx.org/download/nginx-1.14.2.tar.gz

  Nginx-rtmp-module地址: https://github.com/arut/nginx-rtmp-module

二.执行安装命令

  备份nginx原文件

cp /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/nginx/sbin/nginx.bak.201812.1.rtmp 

  下载模块并解压:

cd /thirdparties

wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

unzip  master.zip

  添加模块并编译openresty(注意:重新编译的时候,记得一定要把以前编译过的模块一同加到configure参数里面)

查看原来的模块
/usr/local/openresty/nginx/sbin/nginx -V 
cd /thirdparties/openresty-1.11.2.2

./configure --prefix=/usr/local/openresty  --add-module=/thirdparties/nginx-rtmp-module-master --with-http_ssl_module

make

  停止nginx

/usr/local/openresty/nginx/sbin/nginx -s stop

  备份nginx原文件

mv /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/nginx/sbin/nginx.bak.201812.origin.rtmp 

  将编译后的nginx文件覆盖原文件并重启nginx

cp /thirdparties/openresty-1.11.2.2/build/nginx-1.11.2/objs/nginx /usr/local/openresty/nginx/sbin
/usr/local/openresty/nginx/sbin/nginx
查看module是否已经加入到nginx
/usr/local/openresty/nginx/sbin/nginx -V

三.nginx的配置

  在添加完模块后nginx的配置文件( /usr/local/nginx/conf/nginx.config)中要增加对rtmp的配置

  与http {... ...}同级的地方配置rtmp

  

  events {
    use epoll;
    worker_connections 1024;
  }

#RTMP服务
rtmp {
server {
listen ; #//服务端口
chunk_size ; #//数据传输块的大小
application vod {
play /opt/video; #//视频文件存放位置。
}
#直播
application live{
live on;
record off; #on时将流转换成flv视频文件
#record all;
record_path /opt/video/hls;
#record_max_size 50M;
record_max_size 2M;
       notify_method get;#鉴权        
       on_publish http://localhost:8081/chat_auth;#鉴权
            hls on; #这个参数把直播服务器改造成实时回放服务器。
wait_key on; #对视频切片进行保护,这样就不会产生马赛克了
hls_path /opt/video/hls; #切片视频文件存放位置
hls_fragment 600s; #设置HLS片段长度
hls_playlist_length 1m; #设置HLS播放列表长度,这里设置的是10分钟
hls_continuous on; #连续模式
hls_cleanup on; #对多余的切片进行删除
hls_nested on; #嵌套模式
allow play all;
}
}
}

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 ;
keepalive_timeout ; #gzip on; server {
listen ;
server_name rtmp_server; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
}
location /chat_auth {
proxy_pass https://api.xxxx.com/item_chat_api/v1/account/platform/auth;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# 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 ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 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;
# }
#} }

注意:

  1. 如果不存在文件夹“/opt/video”、“/opt/video/hls”则要创建一个,并且要改成可读可写的权限(chmod  777 /opt/video)

  2. 防火墙是否通:

iptables -I INPUT -p tcp -m state --state NEW --dport 1935 -j ACCEPT #放行1935端口的 NEW状态请求
service iptables save #保存规则
service iptables restart #重启防火墙保证新的规则加载进来

参考:

  https://blog.csdn.net/qzcsu/article/details/72782759

  https://blog.csdn.net/qq_36510261/article/details/78971387

  https://blog.csdn.net/zhiyuan_2007/article/details/52003713

  https://www.cnblogs.com/lidabo/p/7099501.html

java代码鉴权:

@ResponseBody()
@RequestMapping(value="/auth", method={RequestMethod.GET,RequestMethod.POST})
public void auth(HttpServletRequest request, HttpServletResponse response, @RequestParam(required = true)String auth_key,
@RequestParam(required = false) String jsonpcallback) {
//openId$userId$orderId
logger.info("auth auth_key:{}",auth_key);
RpcResponseDTO<Boolean> rpcResult = new RpcResponseDTO<>();
String fail= "{\"code\":\"500\",\"detail\":\"sys error\"}";
String succ= "{\"code\":\"200\",\"detail\":\"SUCCESS\"}";
String result = fail;
if (StringUtils.isEmpty(auth_key)) {
response.setStatus(500);
}else {
String[] auth = auth_key.split("\\$");
logger.info("auth auth[0]:{},auth[1]:{},auth[2]:{}",auth[0],auth[1],auth[2]);
if (auth.length!=3) {
response.setStatus(500);
}else {
RtmpAuthParam param = new RtmpAuthParam();
param.setOpenId(auth[0]);
param.setUserId(Long.parseLong(auth[1]));
param.setOrderId(Long.parseLong(auth[2]));
rpcResult = platformAccountRpcService.validateRtmpAuth(Request.build(param));
logger.info("auth rpcResult:{}",JsonHelper.getJSONString(rpcResult));
if (!rpcResult.hasError()&&rpcResult.getPayload()!=null&&rpcResult.getPayload()) {
response.setStatus(200);
result = succ;
}else {
response.setStatus(500);
}
}
}
logger.info("auth result:{}",result);
SpringMVCHelper.renderText(response,result);
}

Nginx与Nginx-rtmp-module搭建RTMP视频直播和点播服务器的更多相关文章

  1. 使用 nginx 和 rtmp 插件搭建视频直播和点播服务器

    使用 nginx 和 rtmp 模块 ,可以很容易地搭建一个视频直播和点播服务器出来. 首先,看一下最经典的参考文献: How to set up your own private RTMP serv ...

  2. 利用Nginx搭建RTMP视频直播,点播服务器,ffmpeg推流,回看

        一.环境和工具 ubuntu 14.04 desktop 不用server的原因是一部分的演示用到了linux视频播放和直播软件,自己还要装桌面,麻烦. 不建议使用 最新的16TLS,我一开始 ...

  3. 在Windows下搭建基于nginx的视频直播和点播系统

    http://my.oschina.net/gaga/blog/478480 一.软件准备 由于nginx原生是为linux服务的,因此官方并没有编译好的windows版本可以下载,要在windows ...

  4. EasyDSS流媒体服务器软件(支持RTMP/HLS/HTTP-FLV/视频点播/视频直播)-正式环境安装部署攻略

    EasyDSS流媒体服务器软件,提供一站式的转码.点播.直播.时移回放服务,极大地简化了开发和集成的工作. 其中,点播功能主要包含:上传.转码.分发.直播功能,主要包含:直播.录像, 直播支持RTMP ...

  5. 基于开源Red5搭建的视频直播平台

    开始之前,为了便于大家了解Red5,此处引用网络文字,非原创 引言 流媒体文件是目前非常流行的网络媒体格式之一,这种文件允许用户一边下载一边播放,从而大大减少了用户等待播放的时间.另外通过网络播放流媒 ...

  6. Centos7.5 搭建Red5视频直播服务器

    一.安装java环境 yum install java-1.7.0-openjdk 详细步骤请参考 http://www.cnblogs.com/java-qzq/p/5845509.html 我的这 ...

  7. flex4+fms3.5+cs4开发实时音视频直播及点播详解

    开发工具及环境: 1)flash builder4 2)flash cs4 3)flash media server3.5 fms部分 fms是adobe的流媒体服务器,不过是收费的,价格大概是ora ...

  8. Android使用FFMpeg实现推送视频直播流到服务器

    背景 在过去的2015年中,视频直播页的新宠无疑是户外直播.随着4G网络的普及和覆盖率的提升,主播可以在户外通过手机进行直播.而观众也愿意为这种可以足不出户而观天下事的服务买单.基于这样的背景,本文主 ...

  9. [RTMP] 国内各大视频直播CDN厂商推流抢流行为分析

    背景 当存在一个推流客户端正在向rtmp://xxx.com/live/yyy推流时,又有另外一个推流客户端同时对这个地址进行推流,会发生什么呢? 查阅了 Adobe RTMP Spec 发现规范本身 ...

随机推荐

  1. Ocelot简易教程(二)之快速开始2

    为什么这篇的标题叫"Ocelot简易教程(二)之快速开始2"呢,因为很多朋友跟我说上一篇" Ocelot简易教程(二)之快速开始1"内容太少了,只是简单介绍Oc ...

  2. redis 系列2 知识点概述

    一.概述 Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 它支持多种类型的数据结构,如 字符串(strings), 散列(hashes), 列表 ...

  3. sql server 索引阐述系列三 表的堆组织

    一.   概述 这一节来详细介绍堆组织,通过讲解堆的结构,堆与非聚集索引的关系,堆的应用场景,堆与聚集索引的存储空间占用,堆的页拆分现象,最后堆的使用建议 ,这几个维度来描述堆组织.在sqlserve ...

  4. [ Talk is Cheap Show me the CODE ] : jQuery Mobile页面布局

    当我们专注地研究人类生活的空虚,并考虑荣华富贵空幻无常时,也许我们正在阿谀逢迎自己懒惰的天性. Written In The Font 为了app的手机端,我选择了 jQuery Mobile  ,学 ...

  5. DWR第六篇之文件下载

    1. 在第五篇架构基础上进行修改 2. 修改jsp页面 <html> <head> <base href="<%=basePath%>"& ...

  6. SpringBoot2.0应用(五):SpringBoot2.0整合MyBatis

    如何整合MyBatis 1.pom依赖 <dependency> <groupId>org.mybatis.spring.boot</groupId> <ar ...

  7. 为Spring Cloud Config插上管理的翅膀

    最近一致在更新Spring Cloud Config的相关内容,主要也是为这篇埋个伏笔,相信不少调研过Spring Cloud Config的用户都会吐槽它的管理能力太弱.因此,就有了下面为讲推荐的这 ...

  8. 适用于WebApi的SQL注入过滤器

    开发工具:Visual Studio 2017 C#版本:C#7.1 最有效的防止SQL注入的方式是调用数据库时使用参数化查询. 但是如果是接手一个旧的WebApi项目,不想改繁多的数据库访问层的代码 ...

  9. c#使用js上传图片

    前几天朋友说用js上传图片过去遇到点问题,于是自己也想写一个demo这里就把自己挖的坑填了. 话不多说上代码 前台就一个file控件加按钮 <!DOCTYPE html> <html ...

  10. BurpSuiteProxy安装使用

    第一步先安装jdk    https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html  ...