nginx服务器是开源的高性能的http服务器,反向代理服务器,是俄罗斯的大佬开发的,在国内许多公司应用比较多,具体看百科!
反向代理服务器:代理服务器接收internet请求,然后改代理服务器将请求转向内部的服务器,内部服务器将处理的结果返回代理服务器,这个代理服务器就为反向代理服务器!
实时消息传输协议(real time messaging protocol),主要应用在流媒体传输,实时音视频通信的协议!
nginx服务器支持许多功能模块,比如http–mudle,rtmp–mudle等等,不同的mudle占用不同的端口,通过端口,客户端就可以与nginx的mudle进行通信!我们对音视频通过rtmp协议进行推流到nginx服务器,所以需要安装nginx支持的rtmp–mudle!
开始我是在redhat版本上进行安装的,遇到的许多问题:
红帽redhat没有apt-get命令(ubantu),使用yum一直提示没有可用的资源,就安装不了编译依赖工具
去github下载脚本的时候,不知道什么原因也一直down不下来!
于是去下载apt-get,瞎搞了半天,没有成功,就这样前前后后折腾了几天,实在不想折腾了,就去阿里云买了一个低配置的云主机,一个月45左右,接下来环境配置一路畅通!
1.下载nginx,rtmp支持的编译依赖工具
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev
2.下载nginx,以及rtmp源码,然后解压
wget http://nginx.org/download/nginx-1.8.1.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
3.进行解压后的ningx目录,执行configue文件
添加http,rmpt模块
./configure --with-http_ssl_module --add-module=../nginx-
rtmp-module-master
进行一些文件检测
checking for OS
checking for gcc -pipe switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for OpenSSL library ... found
checking for zlib library ... found
产生MakeFile文件
creating objs/Makefile
Configuration summary
using system PCRE library
using system OpenSSL library
md5: using OpenSSL library
sha1: using OpenSSL library
using system zlib library
nginx安装目录:/usr/local/nginx
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/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"
4.编译MakeFile:make
make
产生一些临时文件
make[1]: Entering directory `/usr/stay/nginx-1.8.1'
src/core/nginx.c
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I../nginx-rtmp-module-master -I s
rc/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_log.o \
src/core/ngx_log.c
................
c -o objs/nginx \
objs/src/core/nginx.o \
objs/src/core/ngx_log.o \
objs/src/event/ngx_event_posted.o \
objs/src/event/ngx_event_accept.o
ake[1]: Leaving directory `/usr/stay/nginx-1.8.1'
make -f objs/Makefile manpage
make[1]: Entering directory `/usr/stay/nginx-1.8.1'
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/usr/stay/nginx-1.8.1'
5.编译完成之后,进行安装:make install
make install
进行文件的拷贝,到/usr/local/nginx
make[1]: Entering directory `/usr/stay/nginx-1.8.1'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' || mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' || mv '/usr/local/nginx/sbin/nginx' '
/usr/local/nginx/sbin/nginx.old'cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' || mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types' || cp conf/mime.types '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
test -f '/usr/local/nginx/conf/fastcgi_params' || cp conf/fastcgi_params '/usr/local/nginx/conf'
cp conf/fastcgi_params '/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' || cp conf/nginx.conf '/usr/local/nginx/conf/nginx.co
nf'cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' || mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/usr/stay/nginx-1.8.1'
6.设置开机启动
sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo update-rc.d nginx defaults
7.启动nginx服务
sudo service nginx start
sudo service nginx stop
这样,服务器配置已经完成,接下来需要进行测试,看是否推流成功!
8.下载ffmpeg源码,并安装(ffmpeg 命令查看是否安装成功)
make
make install
9.配置 nginx-rtmp 服务器,然后sudo service nginx restart重启
在打开 /usr/local/nginx/conf/nginx.conf,在末尾添加如下配置:
rtmp {
server {
listen 1935;//监听端口
chunk_size 4096;
application live {
live on;
record off;
exec ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://localhost/live360p/$name;
}
application live360p {
live on;
record off;
}
}
}
10.进行推流
推流使用obs,ums或者github上的一些demo都可以!
11.在下载的windows版本的ffmpeg的bin ffplay
ffplay rtmp://120.77.182.106:1935/live/test