基于nginx快速搭建直播服务

概要说明

  1. nginx的nginx-rtmp-module模块支持直播推流,以下记录搭建过程及步骤
  2. Demo基于docker的linux环境运行

操作步骤

  1. 编译安装nginx
# 运行docker
docker run --name debian -p1935:1935 -p8888:8888 -it debian /bin/bash

# nginx安装在/root/nginx目录下
# 创建相关文件夹,安装相关依赖库文件
cd /root
mkdir download
mkdir nginx
cd download
apt-get update
apt-get install curl
apt-get install gcc
apt-get install libpcre3 libpcre3-dev
apt-get install openssl libssl-dev
apt-get install zlib1g zlib1g-dev
apt-get install lrzsz
apt-get install make
apt-get install procps  # ps 命令

# 下载并解压nginx和nginx-rtmp-module
curl -o nginx-1.18.0.tar.gz http://nginx.org/download/nginx-1.18.0.tar.gz
curl -o nrm.tar.gz https://codeload.github.com/arut/nginx-rtmp-module/legacy.tar.gz/master
tar -zxvf nginx-1.18.0.tar.gz
tar -zxvf nrm.tar.gz
mv arut-nginx-rtmp-module-afd350e nginx-rtmp-module
cd nginx-1.18.0

# 编译安装nginx
./configure --with-debug --with-http_ssl_module --add-module=/root/download/nginx-rtmp-module --prefix=/root/nginx
make && make install

# 查看nginx安装信息
cd /root/nginx/sbin
./nginx -V
  1. 修改nginx配置文件[/root/nginx/conf/nginx.conf],配置rtmp
user  root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
# 配置rtmp
rtmp {
    server {
        listen 1935;
 		chunk_size 4096;
    	application live{
            live on;
    	}
    }
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;

    server {
        listen       8888;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
        	# 地址路径
            root /root/download/nginx-rtmp-module/;
        }
        #error_page  404              /404.html;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
    }
}
  1. 推流
    使用obs工具推流,推流地址 rtmp://localhost/live

  2. 拉流观看
    使用IINA工具拉流, 拉流地址:rtmp://localhost/live

  3. 推拉流监控
    监控地址 http://localhost:8888/stat

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值