Nginx搭建简单直播服务器

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

 前言

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

服务器环境

Ubuntu 16.04

相关概念

  • RTMP: RTMP协议是Real Time Message Protocol(实时信息传输协议)的缩写,它是由Adobe公司提出的一种应用层的协议。依赖于flash播发器来拉流。

请求样式:rtmp://xxx.xxx.xxx.xxx:1935/ttest(命名空间)/test(推流码)

  • HLS:苹果出的一套Http Live Streaming协议,它的工作原理简单来说就是把一段视频流,分成一个个小的基于HTTP的文件来下载。通过读取.m3u8文件读取一个一个的视频流片段。

请求样式:http://xxx.xxx.xxx.xxx/video(nginx配置路由)/test.m3u8

  • nginx-rtmp-module: 基于Nginx的流媒体Server
[[379346]]

测试工具

1. 推流工具:易推流(ios)

2.拉流工具:VLC media player(pc)

实现步骤

一、安装或升级Nginx

  1. sudo apt-get install software-properties-common python-software-properties 
  2. sudo add-apt-repository ppa:nginx/stable 
  3. sudo apt-get update 
  4. sudo apt-get install nginx 

 二、安装nginx-rtmp-module

  1. sudo apt-get install libnginx-mod-rtmp 

三、编写nginx配置

1. /etc/nginx/nginx.conf

  1. user ubuntu; 
  2. rtmp{ 
  3.     server{ 
  4.         listen 1935; 
  5.         chunk_size 4000; 
  6.         application test{ 
  7.             live on
  8.             record off
  9.             hls on
  10.             hls_path /usr/local/src/nginx/html/test; 
  11.             hls_fragment 1s; 
  12.             hls_playlist_length 3s; 
  13.         }    
  14.     } 

 2. /etc/nginx/sites-enables/default

  1. location /video/ { 
  2.     alias /usr/local/src/nginx/html/godeyeTest/; 
  3.    # 余下三行配置是解决跨域问题 
  4.     add_header Access-Control-Allow-Origin *; 
  5.     add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'
  6.     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

 

责任编辑:姜华 来源: 今日头条
相关推荐

2020-07-23 08:10:54

Nginx服务器流媒体

2021-09-10 10:07:17

Nginx虚拟主机服务器

2018-10-26 09:52:25

Nginx服务器负载均衡

2019-04-08 08:39:47

Nginx代理服务器

2023-10-12 19:46:26

Nginx服务器

2010-08-03 13:26:36

linux搭建NFS服

2016-10-19 08:36:51

2013-05-30 09:25:43

2018-10-29 09:39:34

NginxVSFTP服务器

2016-10-13 15:57:28

nginxphpwindows

2013-07-16 14:44:43

Ubuntutftp服务器

2017-03-06 09:26:56

Nginx服务器 SSL

2019-12-24 14:42:51

Nginx服务器架构

2019-09-10 15:22:17

Nginx服务器架构

2020-05-12 21:17:18

Nginx服务器架构

2019-01-10 11:12:15

Nginx服务器架构

2018-10-12 08:43:54

2014-08-06 11:25:00

LinuxSVN服务器

2019-05-08 14:37:49

Web服务器HTTP

2009-09-17 16:06:18

点赞
收藏

51CTO技术栈公众号