在Mac上搭建Nginx服务器(视频直播)

    xiaoxiao2024-03-28  5

    在Mac上搭建Nginx服务器

    前言:这里搭建额Nginx服务器,主要是起来作为视频直播推流拉流的中转站(流媒体处理服务器).

    按照下面的步骤开始:

    1. 安装Homebrew,执行命令

    Homebrew简称brew,是macOS上的软件管理包工具,可以在mac中卸载和安装软件,打开终端,执行下面

    命令行,安装brew.

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    2.安装Nginx服务器

    增加对Nginx的拓展,也就是从github上下载,homebrew对Nginx的拓展

    brew tap homebrew/nginx

    3.增加Nginx服务器和rtmp模块

    brew install nginx-full --with-rtmp-module

    4.配置Nginx的ramp模块

    查看nginx-full信息

    brew info nginx-full

    执行上面的命令后,我们可以看到如下信息

    Docroot is: /usr/local/var/www The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo nginx will load all files in /usr/local/etc/nginx/servers/. - Tips - $ sudo chown root:wheel /usr/local/Cellar/nginx-full/1.10.1/bin/nginx $ sudo chmod u+s /usr/local/Cellar/nginx-full/1.10.1/bin/nginx Reload config: $ nginx -s reload #重新加载配置文件 Reopen Logfile: $ nginx -s reopen #再次打开日志文件 Stop process: $ nginx -s stop #停止服务器 Waiting on exit process $ nginx -s quit #退出服务器

    从上面可以看出,

    Naginx安装所在位置

    /usr/local/Cellar/nginx-full/

    Nginx配置文件所在位置

    /usr/local/etc/nginx/nginx.conf

    Nginx服务器根目录所在位置

    /usr/local/var/www

    执行命令,测试下是否成功启动Nginx服务器

    (这注意:naginx关机重启之后是关闭的,执行下面命令开启,如果不能,直接执行命令nginx开启服务器)

    /usr/local/Cellar/nginx-full/1.10.0/bin/nginx

    在浏览器中输入:# ,如果出现下图所示,则开启成功

    ##5.修改Nginx.conf配置文件,配置rtmp

    用xcode打开Nginx.conf,找到/usr/local/etc/nginx/nginx.conf文件,用xocde打开,打开之后,在文件的最后

    补上一下代码段:

    http { …… } #在http节点下面(也就是文件的尾部)加上rtmp配置: rtmp { server { listen 1935; application live { live on; record off; } } }

    说明:

    rtmp是协议名称

    server 说明内部中是服务器相关配置

    listen 监听的端口号, rtmp协议的默认端口号是1935

    application 访问的应用路径是 live

    live on; 开启实时

    record off; 不记录数据

    6.保存文件后,重新加载nginx的配置文件

    nginx -s reload

    ##7.安装ffmpeg工具

    brew install ffmpeg

    安装ffmpeg需要一段时间,这里提供一个支持rtmp协议的视频播放器.Mac下可以用FLV

    8.通过ffmpeg命令进行推流

    ffmpeg -re -i 你的视频文件的绝对路径(如/Users/lideshan/Downloads/liveVideo.mp4) -vcodec copy -f flv rtmp://localhost:1935/live/room

    - 说明: - localhost 指的是我们本地电脑(IP地址) - live是app访问路径 - room是推流上去的路径(可以随意写,拉流的时候根据这个不同的路径标识拉取不同的流(主播))

    9.验证推流上去的流,下面通过FLV播放器拉流

    电脑上打开vlc这个播放器软件 点击File—->Open Network 在弹出来的框中选择Network然后输入URL:

    rtmp://localhost:1935/live/room

    10.可能出现的问题

    - 找不到C语言的编译器clang 错误信息: checking for OS + Darwin 15.3.0 x86_64 checking for C compiler ... not found ./configure: error: C compiler clang is not found

    解决办法:需要去apple官网[下载](https://developer.apple.com/download/more/)命令行工具,安装即可. 注意命令行工具的版本需要和你的Xcode对应.
    转载请注明原文地址: https://ju.6miu.com/read-1287426.html
    最新回复(0)