1. 更新 环境
yum update #更新所有东东
2. 安装 gcc 环境
yum -y install gcc gcc-c++ # 编译nginx时依赖gcc环境
3. 安装 pcre
yum -y install pcre pcre-devel # nginx支持重写功能
4. 安装 zlib
yum -y install zlib zlib-devel #nginx使用zlib对http包内容进行gzip压缩
5. 安装 openssl
yum -y install openssl openssl-devel # 安全套接字层密码库,用于通信加密
6、下载 nginx-rtmp-module
想支持 rtmp 就得装这个。nginx-rtmp-module 的官方 github 地址:https://github.com/arut/nginx-rtmp-module。解压后记住路径就不理他了。
源码包下载地址:https://nginx.org/en/download.html,要选就选最新的,嘿嘿。。
解压它,到解压后的文件夹目录下右键打开终端。命令如下:
./config --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module --add-module=/usr/local/111/nginx-rtmp-module-1.2.0
#把刚才的东东都加上去,下了不用不是浪费。最后一个路径自己替换为自己的路径
接下来依次就是 make 命令 和 make install 命令了。
安装完毕,到 usr/local/nginx/sbin 下
./nginx -V
就可以看到自己的 nginx 支持什么模式了。
接着到上层目录 conf 下,打开nginx.conf,在里面找到 http 字眼。在上面加入下面这段
rtmp
{
server
{
listen 1935; #端口
chunk_size 4000;
application hls #记住这个名字
{
live on;
hls on;
hls_path /usr/local/111/html/hls; #缓存路径
hls_fragment 5s; #缓存5s
}
}
}
保存这家伙,别忘了在上面的缓存路径下该创建的文件夹创建了。它是懒得帮你创建的。回到 usr/local/nginx/sbin 开启服务器
./nginx
然后就不晓得开了没有。查看开了没有吧
ps -ef | grep nginx # 查看服务进程
昂,这亚子就是开启了。
关闭防火墙,VM开启桥接模式。关闭防火墙,VM开启桥接模式。关闭防火墙,VM开启桥接模式。关闭防火墙,VM开启桥接模式。
rtmp://vm的ip:1935/hls 这个就是你要推流的地址。在其他电脑的浏览器直接打开你 vm 的 ip 是能连接到你的服务器的。这亚子: