Mac搭建nginx+rtmp服务器

Mac搭建nginx+rtmp服务器

概述

Mac安装RTMP服务器过程记录下来!nginx

1、安装Homebrew

执行命令:git

1github

2ruby

3服务器

 

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

 

若是已经安装过,而想要卸载:curl

1ui

2url

3spa

 

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

 

若是已经安装过,则不用安装!

2、安装nginx

先glone nginx项目到本地:

1

2

3

 

brew tap homebrew/nginx

 

执行安装:

1

2

3

 

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

 

经过操做以上步骤,nginx和rtmp模块就安装好了

3、运行nginx

执行命令:

1

2

3

 

nginx

 

出现以下页面信息,表示nginx服务器搭建成功了,并且已经安装了RTMP模块了:

image

4、配置nginx和rtmp

下面开始来配置nginx的rtmp模块。首先,咱们要看看nginx安装到哪里了:

1

2

3

 

brew info nginx-full

 

出现以下相似信息:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

 

==> 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 chown root:wheel /usr/local/Cellar/nginx-full/1.10.0/bin/nginx

$ sudo chmod u+s /usr/local/Cellar/nginx-full/1.10.0/bin/nginx

Reload config:

$ nginx -s reload

Reopen Logfile:

$ nginx -s reopen

Stop process:

$ nginx -s stop

Waiting on exit process

$ nginx -s quit

 

To have launchd start homebrew/nginx/nginx-full now and restart at login:

  brew services start homebrew/nginx/nginx-full

Or, if you don't want/need a background service you can just run:

  nginx

 

从这些信息中,能够看到nginx.conf文件在:

1

2

3

 

/usr/local/etc/nginx/nginx.conf

 

nginx完整路径:

1

2

3

 

/usr/local/Cellar/nginx-full/1.10.0/bin/nginx

 

经过如下打开nginx.conf配置文件来配置:

1

2

3

 

vi /usr/local/etc/nginx/nginx.conf

 

直接滚动到最后一行,以就是在http {} 以后:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

 

http {

    这里默认就有的,不用管这些

}

 

# 在http节点后面加上rtmp配置:

rtmp {

    server {

        listen 5920;

        application rtmplive {

            live on;

            record off;

        }

    }

}

 

重启nginx:

1

2

3

 

/usr/local/Cellar/nginx-full/1.10.0/bin/nginx -s reload

 

5、安装ffmpeg

输入如下命令来安装ffmpeg:

1

2

3

 

brew install ffmpeg

 

安装这个须要等一段时间,而后准备一个视频文件做为来推流,咱们在安装一个支持rtmp协议的视频播放器,Mac下能够用VLC。

6、ffmpeg推流

1

2

3

 

ffmpeg -re -i /Users/huangyibiao/Desktop/test.mov -vcodec libx264 -acodec aac -f flv rtmp://localhost:5920/rtmplive/room

 

将视频推流到服务器后,打开VLC,而后file->open network->输入:

1

2

3

 

rtmp://localhost:5920/rtmplive/room

 

观看视频!

//查看 nginx

你能够用这两个命令,找安装启用的路径 netstat -tnlp|grep nginx 而后看到一行记录,复制最后的一个数据(进程ID) ps -aux |grep 进程ID 就能够看到 NINGX的启动方式了。 若是你如今不知道,而且没重动NIGNX,则能够 find /|grep nginx.conf
相关文章
相关标签/搜索