目录
- 安装nginx
- 启动nginx
【导读】今天搭建了一个非常简单的流媒体服务器,使用ffmpeg推流到nginx服务器,并用VLC播放器订阅这路媒体流播放出来。
1. 安装nginx
1.1 拉取nginx到本地,执行命令:
brew tap homebrew/nginx
如果提示brew不识别,执行如下命令:
ruby -e "$(curl -fsSL raw.githubusercontent.com/Homebrew/in…)"
如果提示错误:
Error: homebrew/nginx was deprecated. This tap is now empty as all its formulae were migrated.
则执行如下命令:
brew tap denji/nginx
1.2 安装nginx及相关模块
安装nginx以及rtmp协议模块,执行如下命令:
brew install nginx-full --with-rtmp-module
如果提示如下报错:
==> Installing nginx-full from denji/nginx
Error: Xcode alone is not sufficient on High Sierra.
Install the Command Line Tools:
xcode-select --install
则执行命令:
xcode-select --install
出现询问弹窗,点击同意,提示如图的弹窗后表示安装成功。
注意:上述截图来自于mac系统。
之后继续执行上一个命令,结果如下:
==> Installing nginx-full from denji/nginx ==> Installing dependencies for denji/nginx/nginx-full: pcre, openssl and rtmp-nginx-module ==> Installing denji/nginx/nginx-full dependency: pcre ==> Downloading homebrew.bintray.com/bottles/pcr… ######################################################################## 100.0% ==> Pouring pcre-8.42.high_sierra.bottle.tar.gz ? /usr/local/Cellar/pcre/8.42: 204 files, 5.3MB ==> Installing denji/nginx/nginx-full dependency: openssl ==> Downloading homebrew.bintray.com/bottles/ope…. ######################################################################## 100.0% ==> Pouring openssl-1.0.2p.high_sierra.bottle.tar.gz ==> Caveats A CA file has been bootstrapped using certificates from the SystemRoots keychain. To add additional certificates (e.g. the certificates added in the System keychain), place .pem files in /usr/local/etc/openssl/certs
and run /usr/local/opt/openssl/bin/c_rehash
openssl is keg-only, which means it was not symlinked into /usr/local, because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
If you need to have openssl first in your PATH run: echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
For compilers to find openssl you may need to set: export LDFLAGS="-L/usr/local/opt/openssl/lib" export CPPFLAGS="-I/usr/local/opt/openssl/include"
For pkg-config to find openssl you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
==> Summary ? /usr/local/Cellar/openssl/1.0.2p: 1,793 files, 12.3MB ==> Installing denji/nginx/nginx-full dependency: rtmp-nginx-module ==> Downloading github.com/sergey-drya… ==> Downloading from codeload.github.com/sergey-drya… ######################################################################## 100.0% ==> Downloading github.com/sergey-drya… ######################################################################## 100.0% ==> Patching ==> Applying v1.1.7.10...504b9ee.diff patching file .gitignore patching file README.md patching file config patching file dash/ngx_rtmp_dash_module.c patching file doc/README.md patching file doc/directives.md patching file hls/ngx_rtmp_hls_module.c patching file hls/ngx_rtmp_mpegts.c patching file hls/ngx_rtmp_mpegts.h patching file hls/ngx_rtmp_mpegts_crc.c patching file hls/ngx_rtmp_mpegts_crc.h patching file ngx_rtmp.c patching file ngx_rtmp_access_module.c patching file ngx_rtmp_amf.c patching file ngx_rtmp_auto_push_module.c patching file ngx_rtmp_cmd_module.h patching file ngx_rtmp_codec_module.c patching file ngx_rtmp_core_module.c patching file ngx_rtmp_eval.c patching file ngx_rtmp_exec_module.c patching file ngx_rtmp_handshake.c patching file ngx_rtmp_init.c patching file ngx_rtmp_live_module.c patching file ngx_rtmp_live_module.h patching file ngx_rtmp_netcall_module.c patching file ngx_rtmp_notify_module.c patching file ngx_rtmp_record_module.c patching file ngx_rtmp_record_module.h patching file ngx_rtmp_shared.c patching file ngx_rtmp_version.h ? /usr/local/Cellar/rtmp-nginx-module/1.1.7.11-dev_3: 94 files, 1.4MB, built in 21 seconds ==> Installing denji/nginx/nginx-full --with-rtmp-module ==> Downloading nginx.org/download/ng… ######################################################################## 100.0% ==> ./configure --prefix=/usr/local/Cellar/nginx-full/1.15.6 --with-http_ssl_mod ==> make install ==> Caveats 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 Run port 80: sudo chmod u+s /usr/local/opt/nginx-full/bin/nginx Reload config: nginx -s reopen Stop process: nginx -s quit
To have launchd start denji/nginx/nginx-full now and restart at login: brew services start denji/nginx/nginx-full Or, if you don't want/need a background service you can just run: nginx ==> Summary ? /usr/local/Cellar/nginx-full/1.15.6: 8 files, 1.2MB, built in 1 minute ==> Caveats ==> openssl A CA file has been bootstrapped using certificates from the SystemRoots keychain. To add additional certificates (e.g. the certificates added in the System keychain), place .pem files in /usr/local/etc/openssl/certs and run /usr/local/opt/openssl/bin/c_rehash openssl is keg-only, which means it was not symlinked into /usr/local, because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries. If you need to have openssl first in your PATH run: echo 'export PATH="/usr/local/opt/openssl/bin: sudo chown root:wheel /usr/local/opt/nginx-full/bin/nginx nginx -s reload Reopen Logfile: nginx -s stop Waiting on exit process $ nginx -s quit To have launchd start denji/nginx/nginx-full now and restart at login: brew services start denji/nginx/nginx-full Or, if you don't want/need a background service you can just run: nginx
2. 启动nginx
至此,nginx流媒体服务器就安装成功了。接下来运行nginx,运行如下命令:
nginx
测试nginx服务器是否可用,打开浏览器,输入http://localhost:8080 回车。
如果出现下图的信息,则表示nginx服务器可用。
然后,就可以向默认的1935端口推rtmp视频流了。