Mac搭建nginx+rtmp服務器
記錄下安裝rtmp的過程
一、安裝Homebrew
確認已經(jīng)安裝了Homebrew,可以通過brew -v查看版本的方式查看是否已經(jīng)安裝過,這個不用過多解釋。
~ 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
安裝過程我也是網(wǎng)上查來的,如果可以正常的安裝,我也就不寫這篇筆記了,首先安裝您可能搜到的步驟進行安裝:
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)
到此,繼續(xù)執(zhí)行下面的命令:
~ 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”。那么我們先執(zhí)行再說:
~ 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
那么 安裝過程到此完成了。
如果遇到端口被占用的問題,可以自己搜索下解決,目前安裝過程就到此為止了。