搭建 nginx rtmp 推流服务器

2017-10-13  本文已影响277人  czins

一、下载相关源码:
nginx

wget http://nginx.org/download/nginx-1.12.1.tar.gz

pcre

wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz

openssl

wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_0f.tar.gz

zlib

wget http://www.zlib.net/zlib-1.2.11.tar.gz

nginx-rtmp-module

wget https://github.com/arut/nginx-rtmp-module/archive/v1.2.0.tar.gz -O nginx-rtmp-module-1.2.0.tar.gz

二、编译源码:
openssl

// 解压
tar -xzf openssl-OpenSSL_1_1_0f.tar.gz
cd openssl-OpenSSL_1_1_0f
// 设置生成输出目录
mkdir bin
./config --prefix=`pwd`/bin
// 编译
make install

pcre

cd ..
tar -xzf pcre-8.41.tar.gz
cd pcre-8.41
./configure
make install

zlib

cd ../
tar -xzf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make install

nginx
1、修改编译 OpenSSL 的配置文件:

vim /root/nginx/nginx-1.12.1/auto/lib/openssl/conf
// 在 MacPorts 判断的下面追加下面的代码
# 添加自定义配置
 if [ $ngx_found = no ]; then

    # 自定义OpenSSL编译路径

    ngx_feature="OpenSSL library in /root/nginx/openssl-OpenSSL_1_1_0f/bin/"
    # 头文件路径
    ngx_feature_path="/root/nginx/openssl-OpenSSL_1_1_0f/bin/include"
    # so 库路径 
    if [ $NGX_RPATH = YES ]; then
        ngx_feature_libs="-R/root/nginx/openssl-OpenSSL_1_1_0f/bin/lib -L/root/nginx/openssl-OpenSSL_1_1_0f/bin/lib -lssl -lcrypto $NGX_LIBDL"
    else
        ngx_feature_libs="-L/root/nginx/openssl-OpenSSL_1_1_0f/bin/lib -lssl -lcrypto $NGX_LIBDL"
    fi
        .auto/feature
 fi

2、编译

cd ..
tar -xzf nginx-1.12.1.tar.gz
// 找到 nginx-rtmp-module 的解压目录
tar -xzf nginx-rtmp-module-1.2.0.tar.gz
cd nginx-rtmp-module-1.2.0
pwd 
// 我这里输出路径 /root/nginx/nginx-rtmp-module-1.2.0
cd ../nginx-1.12.1
// 生成 Makefile
./configure --prefix=`pwd`/bin --add-module=/root/nginx/nginx-rtmp-module-1.2.0
// 编译
make install

3、配置 /etc/ld.so.conf 加入 so 库的查找路径

/root/nginx/openssl-OpenSSL_1_1_0f/bin/lib
// 运行下面的命令,使配置生效
ldconfig 

4、运行

cd ~/nginx/nginx-1.12.1/bin/sbin
./nginx

5、配置阿里云服务器的入口端口 1935、8080,供外网IP访问。

屏幕快照 2017-10-13 上午2.12.50.png

6、修改 nginx 配置文件:

cd ~/nginx/nginx-1.12.1/bin/conf
// 拷贝rtmp配置文件
cp ../../nginx-rtmp-module-1.2.0/test/nginx.conf nginx.conf

并作以下修改:

user root;
location /stat.xsl {
    # 路径为 解压的rtmp模块
    root /root/nginx/nginx-rtmp-module-1.2.0/;
}
location /rtmp-publisher {
    root /root/nginx/nginx-rtmp-module-1.2.0/test;
}
location / {
    root /root/nginx/nginx-rtmp-module-1.2.0/test/www;
}

重启 nginx 服务器:

cd  ~/nginx/nginx-1.12.1/bin/sbin
// 停止
./nginx -s stop
./nginx

7、使用 ffmpeg 命令行测试推流:

ffmpeg -re i test.flv -f flv rtmp://serverip/myapp/mystream

查看推流统计信息:
http://serverip:8080/stat

上一篇下一篇

猜你喜欢

热点阅读