Macbook M1搭建nginx + rtmp和Ubuntu 18.04搭建nginx + rtmp + srs
Mac上搭建nginx + rtmp
mac可以直接使用brew安装,就不用下载源码手动编译了,命令行:brew install nginx-full --with-rtmp-module
注意:这里nginx可执行文件路径变了,不是之前的/usr/local/bin/nginx,而是/opt/homebrew/opt/nginx-full/bin/nginx
1、cd /etc/apt/sources.list.d
2、ls查看有没有 sources-aliyun-0.list 文件 ,如果有执行cp sources-aliyun-0.list sources-aliyun-0.list.bak备份一下,防止出错
3、 将 sources-aliyun-0.list 内的内容替换成以下内容
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse ##测试版源 deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse # 源码 deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse ##测试版源 deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse # Canonical 合作伙伴和附加 deb http://archive.canonical.com/ubuntu/ xenial partner
4、更新源,执行apt-get update
然后重新sudo apt-get install libssl-dev即可。
二、下载和编译源码
这里需要下载三份源码,分别是nginx-1.8.1、nginx-rtme-module和openssl-1.0.2k
nginx-1.8.1地址:https://nginx.org/download/nginx-1.8.1.tar.gz
nginx-rtme-module地址:https://github.com/arut/nginx-rtmp-module.git
openssl-1.0.2k地址:https://www.openssl.org/source/openssl-1.0.2k.tar.gz
在/etc目录下创建个rtmpserver文件夹,然后cd /etc/rtmpserver,没有安装git的要先安装git,执行sudo apt install git,同理没安装wget的要先安装wget,执行sudo apt install wget
依次执行:
wget https://nginx.org/download/nginx-1.8.1.tar.gz && tar xvf nginx-1.8.1.tar.gz
git clone https://github.com/arut/nginx-rtmp-module.git
wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz && tar xvf openssl-1.0.2k.tar.gz
源码下载并解压后是这样的:
现在开始编译。首先cd nginx-1.8.1进入nginx-1.8.1文件夹
执行./configure --with-openssl=../openssl-1.0.2k --add-module=../nginx-rtmp-module
这里指定了openssl和nginx-rtmp-module的路径,名字一定要对应得上,不然会报错的。这个过程时间比较长,耐心等待。
configure结束后,进入nginx-1.8.1文件夹内的objs文件夹,编辑Makefile文件,找到CFLAGS这一行,把这一行的-Werror删掉,然后保存文件。如果不去掉会把warning当作error来处理,结果就是编译不通过,但
是程序员只在意error不在意warning,所以去掉。
接下来执行make && sudo make install ,这个过程时间比较长,耐心等待。
nginx默认安装在/usr/local/nginx路径下,进入该路径下,目录如下:
其中conf文件夹下存放nginx的配置文件,sbin存放nginx的启动文件,先进入sbin文件夹,然后执行命令./nginx,没报错就说明安装成功了。
进入nginx安装路径/usr/local/nginx,进入conf文件夹,编辑nginx.conf文件,添加一个rtmp节点,并配置监听端口,具体如下:
worker_processes 1;
events {
worker_connections 1024;
}
rtmp{
server{
listen 1935;
chunk_size 4096;
application vod{
play /opt/video/vod;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8081;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
保存文件,然后进入sbin文件夹,执行sudo ./nginx -s reload,重新加载配置。