Nginx-RTMP-Win32 安装与使用指南
1. 项目目录结构及介绍
Nginx-RTMP-Win32 是一个适用于Windows系统的Nginx与RTMP模块的集成,其基本目录结构如下:
nginx-rtmp-win32/
├── nginx-<version> # Nginx服务器的主要目录
│ ├── conf # 配置文件目录
│ │ └── nginx.conf # 主配置文件
│ ├── html # 默认网页根目录
│ └── logs # 日志文件目录
└── nginx-rtmp-module # RTMP模块源代码
├── README.md # 模块说明文档
└── ... # 其他相关文件
nginx-<version>
:包含了Nginx服务器的所有文件。conf
:存放Nginx的各种配置文件。nginx.conf
:Nginx服务器的主要配置文件。html
:默认情况下,Nginx会将这个目录作为Web服务器的根目录,存放静态HTML页面。logs
:存放Nginx的日志文件。
2. 项目的启动文件介绍
主要启动文件位于 nginx-<version>
目录下,包括:
-
nginx.exe
: Nginx服务的主进程文件,用于启动、停止和重新加载Nginx配置。- 启动:在命令行中执行
nginx.exe
即可启动Nginx服务器。 - 停止:使用
nginx.exe -s quit
命令优雅地关闭Nginx(等待所有已连接的客户端完成请求后再退出)。 - 重新加载配置:使用
nginx.exe -s reload
命令来立即更新配置文件而无需重启服务。
- 启动:在命令行中执行
3. 项目的配置文件介绍
nginx.conf
nginx.conf
是Nginx服务器的全局配置文件,通常位于 nginx-<version>/conf
目录下。以下是一份基本配置示例,展示了如何添加RTMP模块支持:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
# RTMP configuration block
rtmp {
server {
listen 1935; # RTMP port
chunk_size 4096;
application live {
allow publish all;
deny publish none;
on_publish http://localhost/path/to/on_publish_handler.php; # 可选的on_publish回调处理程序
record off; # 是否记录流到磁盘
exec_record_done /path/to/script.sh $name; # 可选的脚本在流记录完成后运行
}
application hls {
playlist_length 5m;
fragment 10s;
hls on;
hls_path /tmp/hls;
hls_playlist_length 60s;
}
}
}
}
}
在这个配置中:
listen 1935
:指定RTMP服务器监听的端口。application live
和application hls
分别定义了两个应用,一个是用于直播(live
),另一个是用于HLS(hls
)点播。allow publish all;
和deny publish none;
控制谁可以发布流。on_publish
和exec_record_done
分别定义了流发布时和流录制完成后的回调处理器。
请注意,根据实际需求,您可能需要调整这些配置参数以满足您的特定场景。在修改配置后,记得用 nginx.exe -s reload
命令重新加载配置。
以上就是关于Nginx-RTMP-Win32的基本安装和使用指南,祝您在构建流媒体服务的过程中一切顺利!