一、Nginx 介绍
- Nginx是什么?

- Nginx是一个非常出色的HTTP服务器,具有占用内存少,高并发的特点
二、Nginx安装
- 1.克隆github的项目(https://github.com/denji/homebrew-nginx)
brew tap denji/nginx
- 2.安装
brew install nginx-full --with-rtmp-module
查看一下nginx安装在什么地方
brew info nginx-full

nginx配置文件所在位置
/usr/local/etc/nginx/nginx.conf
三、运行nginx
启动nginx,执行命令:
nginx
浏览器地址栏输入:http://localhost:8080

出现以上界面,说明安装成功.
四、配置rtmp
vi /usr/local/etc/nginx/nginx.conf
配置文件长这样:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
include servers/*;
}
我们需要在 在http节点后面加上rtmp配置
rtmp {
server {
listen 1935;
#直播流配置
application rtmplive {
live on;
#为 rtmp 引擎设置最大连接数。默认为 off
max_connections 1024;
}
application hls{
live on;
hls on;
hls_path /usr/local/var/www/hls;
hls_fragment 1s;
}
}
}
编辑完成之后,执行一下重新加载配置文件命令:
nginx -s reload
重启nginx:
sudo /usr/local/opt/nginx-full/bin/nginx -s reload
六、安装ffmepg工具
- 1.安装ffmpeg
brew install ffmpeg
- 2.安装一个支持rtmp协议的视频播放器,Mac下可以用VLC

本地下载一个视频文件路径为
/Users/xx/Desktop/story.mp4
- 执行推流命令
ffmpeg -re -i /Users/xx/Desktop/story.mp4 -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://localhost:1935/rtmplive/room
用vlc 然后打开 VLC 中 的 file -- Open Network, 直接输入代码中的 url:
rtmp://localhost:1935/rtmplive/room
然后进行播放.
手机推流只需把localhost:8080换成自己电脑的ip地址即可:
rtmp://10.0.0.17:1935/rtmplive/room
源博客地址:
mac搭建naginx+rtmp服务器-带你出坑
网友评论