Nginx搭建RTMP推拉流服务器

安装Nginx在mac上有一个很好用的包管理插件,名为homebrew 。具体的安装可以自行去搜索下 。下面就借助Homebrew来安装Nginx 。
首先是拉取Nginx$ brew tap home/nginx执行安装$ brew install nginx-full --with-rtmp-module这里需要注意的就是后面的–with-rtmp-module参数,其意思就是带上rtmp的模块,这样我们才能借助Nginx实现一个rtmp的推拉流服务器 。
安装过程中,homebrew或帮我们自动的安装如pcre,openssl等模块 。因此相对于其他平台的安装方式或者源码安装方式,homebrew贼省心 。
经过稍长的等待时间,带有rtmp模块的Nginx就安装好了 。查看安装详情的命令为:
【Nginx搭建RTMP推拉流服务器】brew info nginx-full就可以看到具体的安装信息了,比如配置文件在哪里,可执行文件又在哪里 。
我这里有如下路径:
- 配置文件路径 /usr/local/etc/nginx/
- web容器路径 /usr/local/var/www
- 可执行文件路径/usr/local/Ceallar/nginx/
配置rtmp
在nginx.conf的HTTP节点后面添加一个同级别的rtmp接单 。具体内容如下:
#usernobody;worker_processes1;#error_loglogs/error.log;#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;error_log/usr/local/var/logs/nginx/error.log debug;pid/usr/local/var/run/nginx.pid;#pidlogs/nginx.pid;events {worker_connections256;}http {includemime.types;default_typeApplication/octet-stream;log_formatmain'$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log/usr/local/var/logs/access.logmain;#access_loglogs/access.logmain;sendfileon;port_in_redirect off;#tcp_nopushon;#keepalive_timeout0;keepalive_timeout65;#gzipon;server {listen8080;server_namelocalhost;#charset koi8-r;#access_loglogs/host.access.logmain;location / {#roothtml;root/usr/local/var/www;indexindex.html index.htm index.php;}#error_page404/404.html;# redirect server error pages to the static page /50x.html#error_page500 502 503 504/50x.html;location = /50x.html {root/usr/local/var/www;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80#location ~ .php$ {proxy_passhttp://127.0.0.1;}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ .php$ {fastcgi_intercept_errors on;#roothtml;root/usr/local/var/www;fastcgi_pass127.0.0.1:9000;#fastcgi_pass unix:/run/php/php7.0-fpm.sock;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includefastcgi_params;}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /.ht {#denyall;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#listen8000;#listensomename:8080;#server_namesomenamealiasanother.alias;#location / {#roothtml;#indexindex.html index.htm;#}#}# HTTPS server##server {#listen443 ssl;#server_namelocalhost;#ssl_certificatecert.pem;#ssl_certificate_keycert.key;#ssl_session_cacheshared:SSL:1m;#ssl_session_timeout5m;#ssl_ciphersHIGH:!aNULL:!MD5;#ssl_prefer_server_cipherson;#location / {#roothtml;#indexindex.html index.htm;#}#}include servers/*;}rtmp {server {listen 1935;chunk_size 4000;application rtmplive {live on;max_connections 1024;}application hls {live on;hls on;hls_path /usr/local/var/www/hls;hls_fragment 1s;}}}最后面hls_path就是待会要用到的推流文件目录了 。一般来说不必创建,如果出现文件夹权限问题的话,手动添加下可读可写权限就可以了 。
安装ffmpeg安装它在其他的平台上可能会超级费劲,但是在Mac上,有了homebrew,那就真的不是事了 。
?$/opt nginx brew install ffmpegUpdating Homebrew...==> Auto-updated Homebrew!Updated 1 tap (caskroom/cask).==> Installing dependencies for ffmpeg: lame, x264, xvid==> Installing ffmpeg dependency: lame==> Downloading https://homebrew.bintray.com/bottles/lame-3.99.5.high_sierra.bottle.1.tar.gz######################################################################## 100.0%==> Pouring lame-3.99.5.high_sierra.bottle.1.tar.gz??/usr/local/Cellar/lame/3.99.5: 27 files, 2MB==> Installing ffmpeg dependency: x264==> Downloading https://homebrew.bintray.com/bottles/x264-r2795.high_sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring x264-r2795.high_sierra.bottle.tar.gz??/usr/local/Cellar/x264/r2795: 11 files, 3.2MB==> Installing ffmpeg dependency: xvid==> Downloading https://homebrew.bintray.com/bottles/xvid-1.3.4.high_sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring xvid-1.3.4.high_sierra.bottle.tar.gz??/usr/local/Cellar/xvid/1.3.4: 10 files, 1.2MB==> Installing ffmpeg==> Downloading https://homebrew.bintray.com/bottles/ffmpeg-3.4.high_sierra.bottle.tar.gz######################################################################## 100.0%==> Pouring ffmpeg-3.4.high_sierra.bottle.tar.gz??/usr/local/Cellar/ffmpeg/3.4: 248 files, 50.9MB


推荐阅读