Mac搭建nginx+rtmp服务器

Mac搭建nginx+rtmp服务器

记录下安装rtmp的过程

一、安装Homebrew

确认已经安装了Homebrew,可以通过brew -v查看版本的方式查看是否已经安装过,这个不用过多解释。

 ~ brew -v
Homebrew 2.1.15
Homebrew/homebrew-core (git revision fcd3; last commit 2019-10-31)

如果没有安装,可以通过下面命令安装:

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

自然卸载命令:

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

如果无法安装,也可以尝试下下面的方法:

/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/Homebrew/install@HEAD/install.sh)"

二、安装nginx

安装过程我也是网上查来的,如果可以正常的安装,我也就不写这篇笔记了,首先安装您可能搜到的步骤进行安装:

brew tap homebrew/nginx

结果我遇到了下面的报错:

Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
abyss               docker2aci          libhttpseverywhere  subversion
amqp-cpp            emscripten          mypy                tup
chronograf          grpc                packmol             znapzend
dnscrypt-proxy      influxdb            rancher-cli
Error: homebrew/nginx was deprecated. This tap is now empty as all its formulae were migrated.

最终在这篇博客找到了原因,根查原因是因为homebrew/nginx的git路径变了。因此需要使用denji/nginx命令来解决这个问题。

通过下面的命令再试试:

~ brew tap denji/nginx

Updating Homebrew...

==> Tapping denji/nginx

Cloning into '/usr/local/Homebrew/Library/Taps/denji/homebrew-nginx'...

remote: Counting objects: 72, done.

remote: Compressing objects: 100% (72/72), done.

remote: Total 72 (delta 1), reused 28 (delta 0), pack-reused 0

Unpacking objects: 100% (72/72), done.

Tapped 62 formulae (162 files, 130.2KB)

到此,继续执行下面的命令:

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

==> Installing nginx-full from denji/nginx
Error: Cannot install denji/nginx/nginx-full because conflicting formulae are installed.
 nginx: because nginx-full symlink with the name for compatibility with nginx
Please `brew unlink nginx` before continuing.
Unlinking removes a formula's symlinks from /usr/local. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.

还是会报错,仔细看错误提示需要“brew unlink nginx”。那么我们先执行再说:

~ brew unlink nginx

接下来配置config,在 /usr/local/etc/nginx 下的nginx.conf

rtmp {
    server {
        listen 1935;
        ping 30s;
        notify_method get;

        application myapp {
            live on;
            record off;
        max_connections 1024;
        }

    #增加对HLS支持开始
    application hls {
        live on;
        hls on;
        hls_path /usr/local/var/www/hls;
        hls_fragment 5s;
    }
    #增加对HLS支持结束
    }
}

三、启动nginx

到此结束,我们启动下nginx:

~ nginx

或者是重启:

~ nginx -s reload

浏览器访问下:http://localhost:8080,看结果是否如下图呢:

image.png

那么 安装过程到此完成了。

如果遇到端口被占用的问题,可以自己搜索下解决,目前安装过程就到此为止了。

你可能感兴趣的:(Mac搭建nginx+rtmp服务器)