nginx本地服务器的搭建

本文介绍如何在Mac电脑上使用Homebrew安装Nginx,并配置RTMP模块来实现流媒体推送功能。文章包括安装步骤、配置方法及解决常见错误提示等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.安装nginx

前文中mac电脑已经安装了homebrew然后使用homebrew安装nginx打开终端输入如下命令

1.brew tap denji/homebrew-nginx

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

查看是否安装成功先启动nginx

然后打开浏览器 输入http://localhost:8080 如果浏览器中有如下内容说明安装成功

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.

Commercial support is available at nginx.com.

Thank you for using nginx.

二.配置rtmp

配置ngingx 和rtmp

1.brew info nginx-full

查看nginx安装的位置找到nginx.conf文件

点击Finder->前往->前往文件夹->输入/usr/local/etc/nginx/nginx.conf

打开后再http节点后加入

如下配置

rtmp {

    server {

        listen 1935;

        chunk_size 4000;

        application rtmplive {

            live on;

            allow play all;

    record off;

        }

    }

}

1.nginx -v 查看版本号 然后替换1.15.4

2./usr/local/Cellar/nginx-full/1.15.4/bin/nginx -s reload

然后再次启动nginx结果出现如下错误

xxmr@MacBook-Pro ~ % nginx

nginx: [emerg] bind() to 0.0.0.0:1935 failed (48: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:1935 failed (48: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:1935 failed (48: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:1935 failed (48: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:1935 failed (48: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)

nginx: [emerg] still could not bind()

不要慌 这个错误需要先关闭当前的nginx  

命令为 nginx -s stop

三.查看本地服务器localhostIP

xxmr@MacBook-Pro ~ % nslookup localhost

这个ip可用来写本地电脑推流,如果使用手机推流则需要使用wifi分配电脑的ip地址

推流命令行

ffmpeg -re -i ~~~~~.mp4 -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://localhost:1935/rtmplive/room

-i 是指定输入位置

-vcodec 是指定视频编码格式

-acodec 是指定音频编码格式

-strict -2 是为了使用ffmpeg 的aac编码 

-f flv指定为flv格式 

此时若推流成功可以新建终端窗口 使用ffplay查看效果 

ffplay rtmp://localhost:1935/rtmplive/room

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值