mac下Nginx搭建RTMP服务器

下载nginx

         wget  wget http://nginx.org/download/nginx-1.15.3.tar.gz

解压

         tar xvf nginx-1.15.3.tar.gz

下载nginx rtmp模块

       wget https://codeload.github.com/arut/nginx-rtmp-module/tar.gz/v1.2.1

解压

       tar xvf v1.2.1

进入nginx目录

       cd nginx-1.15.3

执行:

#--add-module 指向rtmp模块目录
./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1

报错log:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

在这个过程中可能因为环境不同而出现不同错误,缺少openssl,这时候就需要安装openssl。可以通过brew来安装,生成目录在usr/local/Cellar目录下。

再次执行编译

./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1/ --with-openssl=../openssl/

成功后会打印出一些输出信息:

Configuration summary
  + using system PCRE library
  + using OpenSSL library: ../openssl/
  + using system zlib library

  nginx path prefix: "./bin"
  nginx binary file: "./bin/sbin/nginx"
  nginx modules path: "./bin/modules"
  nginx configuration prefix: "./bin/conf"
  nginx configuration file: "./bin/conf/nginx.conf"
  nginx pid file: "./bin/logs/nginx.pid"
  nginx error log file: "./bin/logs/error.log"
  nginx http access log file: "./bin/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

这时候 Makefile文件生成

执行

make install

完成后,会生成在刚刚--prefix指定的目录下。即 :./bin

cd bin/conf

vim nginx.conf 修改为

user root;
worker_processes  1;

error_log  logs/error.log debug;

events {
    worker_connections  1024;
}

rtmp {
    server {
         #注意端口占用
        listen 1935;
        application myapp {
            live on;
            #丢弃闲置5s的连接
            drop_idle_publisher 5s;
        }
    }
}
http {
    server {
        #注意端口占用
        listen      8081;
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            #注意目录
            root /User/user/Desktop/nginx/nginx-rtmp-module-1.2.1/;
        }
        location /control {
            rtmp_control all;
        }
        location /rtmp-publisher {
            #注意目录
            root /User/user/Desktop/nginx/nginx-rtmp-module-1.2.1/test;
        }
        
        location / {
            #注意目录
            root /User/user/Desktop/nginx/nginx-rtmp-module-1.2.1/test/www;
        }
    }
}

这里的内容其实就是从 nginx-rtmp-module-1.2.1/test/nginx.conf中拷贝过来的。

rtmp 默认端口1935

http 默认端口 80

这里设置的http端口和rtmp端口,不能被占用。http端口所以设了8081。

检查端口 :lsof -i:8081

 

配置完成后,就可以启动nginx了

在哪个目录下执行的编译(这里也就是在nginx-1.15.3目录下),就去哪个目录下执行

bin/sbin/nginx  启动服务

bin/sbin/nginx -s stop 停止

 

在浏览器输入

【IP】:8081

能访问就表示配置完成了。

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值