win11下nginx编译并集成nginx-http-flv-module模块
一、win11环境搭建
1、安装Microsoft Visual Studio(安装C++桌面开发组件) 官网: https://visualstudio.microsoft.com/zh-hans/
2、安装 Strawberry Perl 官网:https://strawberryperl.com/
3、安装MSYS2 官网: https://www.msys2.org/
二、三方依赖库、源码准备
1、下载nginx源码 官网:https://nginx.org/ || Github:https://github.com/nginx/nginx/releases
2、下载PCRE 官网: http://www.pcre.org/ || Github:https://github.com/PCRE2Project/pcre2/releases
3、下载zlib 官网:http://zlib.net || Github:https://github.com/madler/zlib/releases
4、下载nginx-http-flv-module Github:https://github.com/winshining/nginx-http-flv-module/releases
5、下载OpenSSL 官网:http://www.openssl.org || Github:https://github.com/openssl/openssl/releases
三方库与源码包示例:
三、构建MakeFile文件
1、解压下载的三方库与源码并移动到nginx根目录(新建)\objs\lib下
2、打开MSYS2切换到nginx源码根目录
3、执行以下命令构建MakeFile(如有版本、路径有差异修改源码与三方库的版本)
auto/configure --with-cc=cl --with-debug --prefix= --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --http-scgi-temp-path=temp/scgi_temp --http-uwsgi-temp-path=temp/uwsgi_temp --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=objs/lib/pcre-8.32 --with-zlib=objs/lib/zlib-1.2.13 --with-openssl=objs/lib/openssl-3.0.9 --with-openssl-opt=no-asm --with-http_ssl_module --with-http_sub_module --with-http_auth_request_module --add-module=objs/lib/nginx-http-flv-module-master
执行成功
四、执行编译
1、打开x64 Native Tools Command Prompt for VS xxxx(xxxx为Microsoft Visual Studio版本)
2、切换到nginx源码根目录
cd D:\Downloads\nginx
3、执行编译:nmake
nmake
4、编译成功后如下(本人未出现异常的情况):将nginx.exe拷贝到上层目录(源码路径下)或者重新下载一个nginx.zip覆盖其中的nginx.exe并配置nginx.conf就可以使用了
五、测试推流
1、安装FFmpeg配置环境变量
2、简单配置一下nginx.config
3、启动nginx并打开CMD执行FFmpeg推流命令
ffmpeg -i mv.mp4 -vcodec libx264 -acodec aac -f flv "rtmp://127.0.0.1:1935/live/100"
4、VLC进行测试(HTTP-FLV、RTMP均可用)
HTTP-FLV: http://127.0.0.1:80/live?app=live&port=1935&stream=100
RTMP: rtmp://127.0.0.1:1935/live/100