不要与 nginx-rtmp-module 一起编译,本模块已包含其全部功能;编译为动态模块时 NGINX 版本必须不低于 1.9.11;建议将 worker_processes 设为 1,否则统计与 vhost 在多进程模式下可能不准确;flv.js 仅支持 H.264 视频和 AAC/MP3 音频,推流编码需匹配。

nginx-http-flv-module
winshiningBSD-2-Clause活跃维护基于 nginx-rtmp-module 扩展的流媒体服务器,支持 HTTP-FLV 拉流、GOP 缓存、多域名虚拟主机和 JSON 格式统计,适合搭建低延迟直播分发服务。
A media streaming server based on nginx-rtmp-module. In addtion to the features nginx-rtmp-module provides, HTTP-FLV, GOP cache, VHosts (one IP for multi domain names) and JSON style statistics are supported now.
./configure --add-module=/path/to/nginx-http-flv-module
make
make installREADME 未说明显存或 GPU 要求;系统支持 Linux(推荐)、FreeBSD、MacOS 和 Windows(功能受限),编译需 GCC 或 MSVC。
基于 nginx-rtmp-module 的流媒体服务器,额外支持 HTTP-FLV 播放、GOP 缓存和虚拟主机
基于 nginx-rtmp-module 扩展的流媒体服务器,支持 HTTP-FLV 拉流、GOP 缓存、多域名虚拟主机和 JSON 格式统计,适合搭建低延迟直播分发服务。
核心能力
- 在 nginx-rtmp-module 全部功能之上增加 HTTP-FLV 播放
- 支持 HTTPS-FLV 与 chunked 分块响应传输
- 提供 GOP 缓存,缩短播放首屏等待
- 支持虚拟主机,单 IP 承载多域名
- 输出 JSON 风格统计并提供录像统计
容易踩的坑
- v1.2.15Version 1.2.15 of nginx-http-flv-module published最新正式版2026-11-01 · 2026-11-01 18:35 UTC
Changelog
- skip live requests in play module.
- remove the last duplicate character in
tcUrlwhen a TLS proxy is used, spotted by @TheRealMattLear, thanks. - fixed a compilation error due to removal of Windows
IOCPin Nginx, spotted by @mxdabc, thanks. - fixed a SIGSEGV bug caused by reading & writing an AMF0 strict array nested too deeply, spotted by @bararchy, thanks.
- fixed a SIGSEGV bug caused by incorrect log format if log level was
debug.
变更列表
- 在 play 模块中跳过直播请求。
- 当使用 TLS 代理时移除
tcUrl中最后一个重复的字节,由 @TheRealMattLear 指出,感谢。 - 修复一个由于 Nginx 移除 Windows 的
ICOP导致的编译错误,由 @mxdabc 指出,感谢。 - 修复一个由于读取和写入嵌套太深的 AMF0 严格数组导致的 SIGSEGV 问题,由 @bararchy 指出,感谢。
- 修复一个如果日志级别为
debug时,由于错误日志格式导致的 SIGSEGV 问题。
- v1.2.14Version 1.2.14 of nginx-http-flv-module published2026-07-04 · 2026-07-04 04:30 UTC
查看更新说明
Changelog
- fixed a SIGSEGV bug caused by receiving an HTTP/1.0 request without a header
Host, spotted by @TaiYou-TW, thanks. - HTTP/3.0 is not supported.
- added
#errordirective to fail compilation with Nginx versions older than 1.2.6.
变更列表
- 修复由于收到没有
Host标头的 HTTP/1.0 请求导致的 SIGSEGV 问题,由 @TaiYou-TW 发现,感谢 。 - 不支持 HTTP/3.0。
- 添加
#error指令,不能与 Nginx 1.2.6 之前的版本一起编译。
- fixed a SIGSEGV bug caused by receiving an HTTP/1.0 request without a header
- v1.2.13Version 1.2.13 of nginx-http-flv-module published2026-02-23 · 2026-02-23 08:45 UTC
查看更新说明
Changelog
- fixed bad status of stop request for record from a non-publish process.
- do not resolve the resolved domain names in
pullandpush. - fixed potential length overflow of
rtmp_socket_dir. - improved recording statistics.
- fixed duplicate writing of audio & video sequence headers.
变更列表
- 修复请求非 publish 进程停止录制时返回错误状态的问题。
- 不解析
pull和push中已经解析过的域名。 - 修复
rtmp_socket_dir长度有潜在溢出风险的问题。 - 改进录制统计数据。
- 修复录制时重复写入音频和视频序列头的问题。
- v1.2.12 Version 1.2.12 of nginx-http-flv-module published2024-12-31 · 2024-12-31 15:53 UTC
查看更新说明
Changelog
- fixed a memory leak bug in relay module and added port text in log.
- added support for
tcp_nopushandtcp_nodelay. - placed access module before gop cache module.
- optimized logging for relay module.
- fixed some compilation errors if compiled with very old Nginx version or compiled on Windows (#237) or Mac (#246).
- improved SPS, PPS and meta processing in gop cache, thanks to @vacing.
- used pids as unix domain sockets' suffixes in auto-push module, thanks to @vacing.
- worked around the buggy option
-mapin FFmpeg (#245), thanks to @streamingsystems. - fixed an endian bug in mp4 vod.
- fixed 'proxy protocol not working' bug (#239), thanks to @streamingsystems.
- fixed a crash bug resulted from 'reload' (#238), thanks to @streamingsystems.
变更列表
- 修复 relay 模块中的一个内存泄漏问题,在日志中加入端口信息。
- 增加
tcp_nopush和tcp_nodelay支持。 - 将 access 模块放置到 gop cache 模块之前。
- 优化 relay 模块的打印日志。
- 修复与很老的 Nginx 版本编译时或者在 Windows (#237) 或者 Mac (#246) 上编译时的编译错误。
- 改进 SPS,PPS 和 meta 在 gop cache 模块中的处理,感谢 @vacing。
- 使用 pid 作为 auto-push 模块中 unix domain socket 的后缀,感谢 @vacing。
- 临时解决 FFmpeg 传递问题选项
-map的问题 (#245),感谢 @streamingsystems。 - 修复 mp4 vod 模块中的一个大小端问题。
- 修复 'proxy protocol not working' 问题 (#239),感谢 @streamingsystems。
- 修复由 'reload' 导致的一个崩溃问题 (#238),感谢 @streamingsystems。
- v1.2.11Version 1.2.11 of nginx-http-flv-module published (fixed #235)2023-03-19 · 2023-03-19 16:01 UTC
查看更新说明
Changelog
- Added single track support for HLS, so video-only and audio-only media can be played properly (#217).
- Made code endian independent (#221).
变更列表
- 添加 HLS 单轨支持,可以正确播放纯视频和纯音频媒体(#217)。
- 代码修改为与大小端无关(#221)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
nginx-http-flv-module
A media streaming server based on nginx-rtmp-module.
中文说明.
Donate if you like this module. Many thanks to you!
Credits
-
Igor Sysoev, the creator of NGINX.
-
Roman Arutyunyan, who created nginx-rtmp-module.
-
Contributors, refer to AUTHORS for details.
Features
-
All features nginx-rtmp-module provides.
-
Other features provided by nginx-http-flv-module vs nginx-rtmp-module:
| Features | nginx-http-flv-module | nginx-rtmp-module | Remarks |
|---|---|---|---|
| HTTP-FLV (HTTP/1.x for play) | √ | x | HTTPS-FLV and chunked response supported |
| GOP cache | √ | x | |
| Virtual Host | √ | x | |
Omit listen directive | √ | See remarks | There MUST be at least one listen directive |
| Audio-only support for RTMP/HTTP-FLV | √ | See remarks | Won't work if wait_video or wait_key is on |
| Single-track support for HLS | √ | x | |
reuseport support | √ | x | |
| Timer for access log | √ | x | |
| JSON style statistics | √ | x | |
| Statistics for recordings | √ | x | |
| Independent of endianness | √ | See remarks | Partially supported in branch big-endian |
| Timeout for play connections | √ | x |
Compatibility
The NGINX version SHOULD be equal to or greater than 1.2.6, the compatibility with other versions is unknown.
Systems supported
- Linux (recommended) / FreeBSD / MacOS / Windows (limited).
Players supported
Note
-
Flash player will be no longer supported officially by Adobe after December 31, 2020, refer to Adobe Flash Player EOL General Information Page for details. Plugins that use flash player won't work after the major browsers subsequently remove flash player.
-
flv.js can only run with browsers that support Media Source Extensions.
Prerequisites
-
GNU make for activating compiler on Unix-like systems to compile software.
-
GCC for compilation on Unix-like systems or MSVC for compilation on Windows.
-
GDB for debug on Unix-like systems.
-
VLC (recommended) or flv.js (recommended) for playing media streams.
-
PCRE for NGINX if regular expressions needed.
-
OpenSSL for NGINX if encrypted access needed.
-
zlib for NGINX if compression needed.
Build
Note
nginx-http-flv-module has all features that nginx-rtmp-module provides, so DON'T compile nginx-http-flv-module along with nginx-rtmp-module.
On Windows
For details about build steps, please refer to Building nginx on the Win32 platform with Visual C, and don't forget to add --add-module=/path/to/nginx-http-flv-module in Run configure script step.
Note
If some compilers which do not support x64 perfectly, VS2010 for example, are used to compile the module, please make sure that the default settings are used (target machine type x86).
On Unix-like systems
Download NGINX and nginx-http-flv-module.
Uncompress them.
cd to NGINX source directory & run this:
Compile the module into NGINX
./configure --add-module=/path/to/nginx-http-flv-module
make
make install
or
Compile the module as a dynamic module
./configure --add-dynamic-module=/path/to/nginx-http-flv-module
make
make install
Note
If the module is compiled as a dynamic module, the NGINX version MUST be equal to or greater than 1.9.11.
Usage
For details of usages of nginx-rtmp-module, please refer to README.md.
Publish
For simplicity, transcoding is not used (so -c copy is used):
ffmpeg -re -i MEDIA_FILE_NAME -c copy -f flv rtmp://example.com[:port]/appname/streamname
Note
Some legacy versions of FFmpeg don't support the option -c copy, the options -vcodec copy -acodec copy can be used instead.
The appname is used to match an application block in rtmp block (see below for details).
The streamname can be specified at will but can NOT be omitted.
The default port for RTMP is 1935, if some other ports were used, :port must be specified.
Play
via HTTP-FLV
http://example.com[:port]/dir?[port=xxx&]app=appname&stream=streamname
Note
-
If ffplay is used in command line to play the stream, the url above MUST be enclosed by quotation marks, or arguments in url will be discarded (some shells not so smart will interpret "&" as "run in background").
-
If flv.js is used to play the stream, make sure that the published stream is encoded properly, for flv.js supports ONLY H.264 encoded video and AAC/MP3 encoded audio.
The dir is used to match location blocks in http block (see below for details).
The default port for HTTP is 80, if some other ports were used, :port must be specified.
The default port for RTMP is 1935, if some other ports were used, port=xxx must be specified.
The value of app (appname) is used to match an application block, but if the requested app appears in several server blocks and those blocks have the same address and port configuration, host name matches server_name directive will be additionally used to identify the requested application block, otherwise the first one is matched.
The value of stream (streamname) is used to match the name of published stream.
Example
Assume that listen directive specified in http block is:
http {
...
server {
listen 8080; #not default port 80
...
location /live {
flv_live on;
}
}
}
And listen directive specified in rtmp block is:
rtmp {
...
server {
listen 1985; #not default port 1935
...
application myapp {
live on;
}
}
}
And the name of published stream is mystream, then the url of playback based on HTTP is:
http://example.com:8080/live?port=1985&app=myapp&stream=mystream
Note
Since some players don't support HTTP chunked transmission, it's better to specify chunked_transfer_encoding off; in location where flv_live on; is specified in this case, or play will fail.
via RTMP
rtmp://example.com[:port]/appname/streamname
via HLS
http://example.com[:port]/dir/streamname.m3u8
via DASH
http://example.com[:port]/dir/streamname.mpd
Sample Pictures
RTMP (JW Player) & HTTP-FLV (VLC)

HTTP-FLV (flv.js)

Example nginx.conf
Note
The directives rtmp_auto_push, rtmp_auto_push_reconnect and rtmp_socket_dir will not function on Windows except on Windows 10 17063 and later versions, because relay in multiple processes mode needs help of Unix domain socket, please refer to Unix domain socket on Windows 10 for details.
It's better to specify the directive worker_processes as 1, because ngx_rtmp_stat_module may not get statistics from a specified worker process in multi-processes mode, for HTTP requests are randomly distributed to worker processes. ngx_rtmp_control_module has the same problem. The problem can be optimized by this patch per-worker-listener.
In addtion, vhost feature is OK in single process mode but not perfect in multi-processes mode yet, waiting to be fixed. For example, the following configuration is OK in multi-processes mode:
rtmp {
...
server {
listen 1935;
server_name domain_name;
application myapp {
...
}
}
}
While the following configuration doesn't work properly for play requests distinated to the second server (whether port is 1935 or not) of non-publisher worker processes:
rtmp {
...
server {
listen 1935;
server_name 1st_domain_name;
application myapp {
...
}
}
server {
listen 1945;
server_name 2nd_domain_name;
application myapp {
...
}
}
}
If NGINX is running in muti-processes mode and socket option SO_REUSEPORT is supported by platform, adding option reuseport for the directive listen will resolve the thundering herd problem.
rtmp {
...
server {
listen 1935 reuseport;
...
}
}
Example configuration
worker_processes 1; #should be 1 for Windows, for it doesn't support Unix domain socket
#worker_processes auto; #from versions 1.3.8 and 1.2.5
#worker_cpu_affinity 0001 0010 0100 1000; #only available on FreeBSD and Linux
#worker_cpu_affinity auto; #from version 1.9.10
error_log logs/error.log error;
#if the module is compiled as a dynamic module and features relevant
#to RTMP are needed, the command below MUST be specified and MUST be
#located before events directive, otherwise the module won't be loaded
#or will be loaded unsuccessfully when NGINX is started
#load_module modules/ngx_http_flv_live_module.so;
events {
worker_connections 4096;
}
http {
include mime.types;
default_type application/octet-stream;
keepalive_timeout 65;
server {
listen 80;
location / {
root /var/www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /live {
flv_live on; #open flv live streaming (subscribe)
chunked_transfer_encoding on; #open 'Transfer-Encoding: chunked' response
add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header 'Cache-Control' 'no-cache';
}
location /dash {
root /tmp;
add_header 'Cache-Control' 'no-cache';
}
location /stat {
#configuration of streaming & recording statistics
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /var/www/rtmp; #specify in where stat.xsl located
}
#if JSON style stat needed, no need to specify
#stat.xsl but a new directive rtmp_stat_format
#location /stat {
# rtmp_stat all;
# rtmp_stat_format json;
#}
location /control {
rtmp_control all; #configuration of control module of rtmp
}
}
}
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /tmp;
rtmp {
out_queue 4096;
out_cork 8;
max_streams 128;
timeout 15s;
drop_idle_publisher 15s;
log_interval 5s; #interval used by log module to log in access.log, it is very useful for debug
log_size 1m; #buffer size used by log module to log in access.log
server {
listen 1935;
server_name www.test.*; #for suffix wildcard matching of virtual host name
application myapp {
live on;
gop_cache on; #open GOP cache for reducing the wating time for the first picture of video
}
application hls {
live on;
hls on;
hls_path /tmp/hls;
}
application dash {
live on;
dash on;
dash_path /tmp/dash;
}
}
server {
listen 1935;
server_name *.test.com; #for prefix wildcard matching of virtual host name
application myapp {
live on;
gop_cache on; #open GOP cache for reducing the wating time for the first picture of video
}
}
server {
listen 1935;
server_name www.test.com; #for completely matching of virtual host name
application myapp {
live on;
gop_cache on; #open GOP cache for reducing the wating time for the first picture of video
}
}
}