【实现方案】Nginx搭建简单直播服务器

前言

使用 Nginx + Nginx-rtmp-module 在Ubuntu 中搭建简单的 rtmp 推流直播服务器。

服务器环境

Ubuntu 16.04

相关概念

  1. RTMP: RTMP协议是Real Time Message Protocol(实时信息传输协议)的缩写,它是由Adobe公司提出的一种应用层的协议。依赖于flash播发器来拉流。
    请求样式:rtmp://xxx.xxx.xxx.xxx:1935/ttest(命名空间)/test(推流码)

  2. HLS:苹果出的一套Http Live Streaming协议,它的工作原理简单来说就是把一段视频流,分成一个个小的基于HTTP的文件来下载。通过读取.m3u8文件读取一个一个的视频流片段。
    请求样式:http://xxx.xxx.xxx.xxx/video(nginx配置路由)/test.m3u8

  3. nginx-rtmp-module: 基于Nginx的流媒体Server

测试工具

  1. 推流工具:易推流(ios)
  2. 拉流工具:VLC media player(pc)

实现步骤

一、安装或升级Nginx
sudo apt-get install software-properties-common python-software-properties
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
二、安装nginx-rtmp-module
sudo apt-get install libnginx-mod-rtmp
三、编写nginx配置
  1. /etc/nginx/nginx.conf
user ubuntu;

rtmp{
	server{
		listen 1935;
		chunk_size 4000;
		application test{
			live on;
			record off;
			hls on;
			hls_path /usr/local/src/nginx/html/test;
			hls_fragment 1s;
			hls_playlist_length 3s;
		}	
	}
}
  1. /etc/nginx/sites-enables/default
	location /video/ {
		alias /usr/local/src/nginx/html/godeyeTest/;
		add_header Access-Control-Allow-Origin *;
		add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
		add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
	}
四、新建路径,重启nginx服务
  1. mkdir 配置中的路径(/usr/local/src/nginx/html/test)
  2. serive nginx restart
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值