基于nginx的rtmp流服务器的搭建,在cenos和ubuntu下的安装

基于nginx的rtmp直播的搭建

一、首先,了解以下协议:
RTMP是Real Time Messaging Protocol实时消息传送协议的缩写,是 Adobe Systems 公司为 Flash 播放器和服务器之间音频、视频和数据传输开发的协议。
二、具体搭建
Centos下搭建nginx服务器
1、建立一个目录来存放,我使用的是:/usr/local/src

cd /usr/local/src

2、 下载nginx-rtmp-module
注:nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module
使用命令下载nginx-rtmp-module

git clone https://github.com/arut/nginx-rtmp-module.git

注意若没有git,使用yum install git来安装

在这里插入图片描述
3、 nginx安装(注意:以上两个最好安装在同一个目录中。方便配置。)

wget https://nginx.org/download/nginx-1.13.4.tar.gz
tar -zxvf nginx-1.13.4.tar.gz  (解压)
cd nginx-1.13.4  (进入目录) 
然后使用以下命令
./configure --prefix=/usr/local/src/nginx  --add-module=../nginx-rtmp-module  --with-http_ssl_module

如果有以下错误提示,那么是依赖项没下载
在这里插入图片描述
需要执行以下命令:
安装工具,用于Nginx和Nginx-RTMP源代码的编译

sudo yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel -y

安装依赖后,继续这项操作

./configure --prefix=/usr/local/src/nginx  --add-module=../nginx-rtmp-module  --with-http_ssl_module

然后使用以下命令进行编译

make && make install

Nginx安装成功测试
进入安装目录/usr/local/nginx,运行命令./sbin/nginx
在这里插入图片描述

注意:以后所有的命令都在/usr/local/nginx目录运行,也nginx配置文件的相对目录。
打开浏览器在地址栏输入:localhost。如果,如下图显示那样就证明您的nginx服务器搭建成功了。
在这里插入图片描述
ubuntu下nginx服务器搭建
1、建立一个目录来存放,我使用的是:/usr/local/src

cd /usr/local/src

2、 下载nginx-rtmp-module
注:nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module
使用命令下载nginx-rtmp-module

git clone https://github.com/arut/nginx-rtmp-module.git

在这里插入图片描述

3、 nginx安装(注意:以上两个最好安装在同一个目录中。方便配置。)
安装依赖:

sudo apt-get install gcc #gcc环境
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。
sudo apt-get install libpcre3 libpcre3-dev
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
sudo apt-get install openssl
wget https://nginx.org/download/nginx-1.13.4.tar.gz

在这里插入图片描述
4、进行解压,并进入目录

tar -zxvf nginx-1.13.4.tar.gz
cd nginx-1.13.4

在这里插入图片描述

然后使用以下命令
./configure --prefix=/usr/local/src/nginx --add-module=…/nginx-rtmp-module --with-http_ssl_module

如果有以下错误提示,那么缺少依赖项没下载
在这里插入图片描述
执行

sudo apt-get install zlib1g-dev
最后再使用以下命令
./configure --prefix=/usr/local/src/nginx  --add-module=../nginx-rtmp-module  --with-http_ssl_module

然后

sudo make

在这里插入图片描述
出现以上内容后,执行以下命令

sudo make install

运行演示
进入安装目录/usr/local/nginx,运行命令./sbin/nginx
在这里插入图片描述
访问localhost
在这里插入图片描述
rtmp的配置
进入安装目录/usr/local/nginx/conf,配置以下文件

nano /usr/local/nginx/conf/nginx.conf
nano /usr/local/nginx/conf/nginx.conf.default
rtmp{
	server{
		listen 1935;
		application live{
			live on;
			}
		}
}

使用obs,和vlc进行推流演示
ubuntu下obs安装

sudo add-apt-repository ppa:obsproject/obs-studio
sudo apt update
sudo apt install obs-studio

图形界面的安装
在Ubuntu的软件商店,查询vlc进行安装。
测试
在obs中,的这里输入rtmp://ip地址:1935/live在这里插入图片描述
在vlc中的媒体->流,找到以下页面
输入:rtmp://ip地址:1935/live
在这里插入图片描述
结果
在这里插入图片描述
完整rtmp的配置

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
        }

        application hls {
            live on;
            hls on;
            hls_path /usr/local/src/nginx/html;

            hls_fragment 10s;

        }
    }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值