MAC 上编译安装nginx-rtmp-module 流媒体服务器
MAC 上编译安装nginx-rtmp-module 流媒体服务器
记录踩坑过程
下载nginx和nginx-rtmp-module
wget http://nginx.org/download/nginx-1.15.3.tar.gz
git clone https://github.com/arut/nginx-rtmp-module
生成makefile
tar -zxvf nginx-1.15.3.tar.gz
cd nginx-1.15.3
./configure --prefix=/data/server/nginx --with-http_ssl_module --add-module=../nginx-rtmp-module
报如下错误:
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
去掉http_rewrite模块:
./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=../nginx-rtmp-module --without-http_rewrite_module
到这一步的时候碰到如下错误:
checking for OpenSSL library ... not found
checking for OpenSSL library in /usr/local/ ... not found
checking for OpenSSL library in /usr/pkg/ ... not found
checking for OpenSSL library in /opt/local/ ... not found
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
执行一下openssl,看是否openssl已经安装。
openssl
如果没有安装,执行下面的命令进行安装:
brew install openssl
有可能最后openssl没有安装到系统会自动搜索的那几个目录。我的mac上就不是。查找openssl 安装目录:
brew info openssl
按照提示加上路径即可:
./configure --prefix=/Users/username/nginx --with-http_ssl_module --add-module=../nginx-rtmp-module --with-openssl=/usr/local/opt/openssl@1.1
成功后出现如下提示:
Configuration summary
+ using system PCRE library
+ using OpenSSL library: /usr/local/opt/openssl@1.1
+ using system zlib library
nginx path prefix: "/Users/chenhailiang/nginx"
nginx binary file: "/Users/chenhailiang/nginx/sbin/nginx"
nginx modules path: "/Users/chenhailiang/nginx/modules"
nginx configuration prefix: "/Users/chenhailiang/nginx/conf"
nginx configuration file: "/Users/chenhailiang/nginx/conf/nginx.conf"
nginx pid file: "/Users/chenhailiang/nginx/logs/nginx.pid"
nginx error log file: "/Users/chenhailiang/nginx/logs/error.log"
nginx http access log file: "/Users/chenhailiang/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp
make
执行make生成二进制文件:
make
报如下错误:
/Library/Developer/CommandLineTools/usr/bin/make -f objs/Makefile
cd /usr/local/opt/openssl@1.1 \
&& if [ -f Makefile ]; then /Library/Developer/CommandLineTools/usr/bin/make clean; fi \
&& ./config --prefix=/usr/local/opt/openssl@1.1/.openssl no-shared no-threads \
&& /Library/Developer/CommandLineTools/usr/bin/make \
&& /Library/Developer/CommandLineTools/usr/bin/make install_sw LIBDIR=lib
/bin/sh: ./config: No such file or directory
make[1]: *** [/usr/local/opt/openssl@1.1/.openssl/include/openssl/ssl.h] Error 127
make: *** [build] Error 2
执行如下的命令,修改一个文件
vim auto/lib/openssl/conf
把下面的几行中的.openssl去掉,然后保存
39 CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
40 CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
41 CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
42 CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
改成
39 CORE_INCS="$CORE_INCS $OPENSSL/include"
40 CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
41 CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
42 CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
注意:修改完之后需要重新执行一遍 configure,否则修改不生效。
再次make成功
make install
执行make install 安装nginx和nginx-rtmp-module到指定目录:
make install
修改配置文件
修改安装目录下面的conf/nginx.conf文件,添加rtmp配置:
rtmp {
server {
listen 1935;
application mytv {
live on;
}
}
}
启动服务
./sbin/nginx -c ./conf/nginx.conf
使用ffmpeg推流
ffmpeg -re -i /Users/username/test_sps_1.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost:1935/mytv/home
ffplay 播放
ffplay -i. rtmp://localhost:1935/mytv/home
打印debug日志
如果需要调试查看debug log,做下面两部操作:
添加--with-debug选项
./configure --prefix=/Users/username/nginx --with-http_ssl_module --add-module=../nginx-rtmp-module --with-debug --with-openssl=/usr/local/opt/openssl@1.1
修改配置文件nginx.conf中的日志配置项:
#error_log logs/error.log info;
修改为
error_log logs/error.log debug;
参考
作者:
HarlanC
博客地址:
http://www.cnblogs.com/harlanc/
个人博客:
http://www.harlancn.me/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出,
原文链接