文章摘要
Foreword Linux 为当前 nginx 添加 rtmp 模块非常的方便, sudo ./configure --add-module + sudo make 就完事儿了,但是windows比较复杂,没有包管理器,所以各个模块的源码要自己找,下面是我在 windows11 下的 nginx with rtmp module 的编译记录。 编译器工具链有 msvc toolchain 、 p…
Foreword Linux 为当前 nginx 添加 rtmp 模块非常的方便, sudo ./configure --add-module + sudo make 就完事儿了,但是windows比较复杂,没有包管理器,所以各个模块的源码要自己找,下面是我在 windows11 下的 nginx with rtmp module 的编译记录。 编译器工具链有 msvc toolchain 、 perl 。 以下是我操作系统的具体信息: OS: Windows 11 Pro x86_64 Kernel: 10.0.22621 CPU: Intel Ultra 7 155H (22) @ 3.000GHz Prerequisite 首先下载 Nginx 的源码,可以使用 git 也可以使用 Mercurial 不过因为后续要借用 git bash 生成 makefile 所以下面统一使用 git 。在写这篇博客时, nginx 的 mainline 为 1.25.4 ,所以下面编译我也用 1.25.4 的版本。 首先在自定义目录(自己想把源码放哪儿就在哪儿打开)打开git-bash 输入下列指令 clone nginx 仓库 git clone https://github.com/nginx/nginx.git cd nginx git checkout release-1.25.4 clone 完成后,要查看一下当前版本所需依赖的版本,输入下列命令查看 cat -n misc/GNUmakefile 我的控制台输出如下,大概可以看到 openssl 的版本是 3.0.13 , zlib 的版本是 1.3.1 , pcre2 的版本是 10.39 8 OBJS = objs.msvc8 9 OPENSSL = openssl-3.0.13 10 ZLIB = zlib-1.3.1 11 PCRE = pcre2-10.39 以下我下载指定版本的依赖源码使用的是 git clone ,当然也可以通过下载压缩包然后解压的方式,这里我给出两种方法所需要的操作步骤 mkdir objs mkdir objs/lib cd objs/lib git clone https://github.com/openssl/openssl.git git clone https://github.com/madler/zlib.git git clone https://github.com/pcre2project/pcre2.git cd openssl git checkout openssl-3.0.13 cd ../zlib/ git checkout v1.3.1 cd ../pcre2/ git checkout pcre2-10.39 然后接着下载 rtmp module 的源码 git clone https://github.com/arut/nginx-rtmp-module.git git checkout v1.2.2 cd ../../.. Main 源码部分的准备已经完成,下面正式开始编译部分,我们重新回到源代码主目录,运行 configuration script ,脚本的具体配置可以参考 nginx官网 但如果想要更完整的 nginx ,即仅仅只是在发行版上增加 rtmp module ,最好的办法是先看看发行版的编译参数 下载 1.25.4 版本,并输入 nginx -V ,可以看到以下参数 ./nginx -V nginx version: nginx/1.25.4 built by cl 16.00.30319.01 for 80x86 built with OpenSSL 3.0.13 30 Jan 2024 TLS SNI support enabled configure arguments: --with-cc=cl --builddir=objs.msvc8 --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.msvc8/lib/pcre2-10.39 --with-zlib=objs.msvc8/lib/zlib-1.3.1 --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_slice_module --with-mail --with-stream --with-stream_realip_module --with-stream_ssl_preread_module --with-openssl=objs.msvc8/lib/openssl-3.0.13 --with-openssl-opt='no-asm no-tests -D_WIN32_WINNT=0x0501' --with-http_ssl_module --with-mail_ssl_module --with-stream_ssl_module 我们根据我们现有的库的位置,修改脚本参数 auto/configure \ --with-cc=cl \ --builddir=objs.msvc8 \ --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-http_v2_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_stub_status_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_auth_request_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_slice_module \ --with-mail \ --with-stream \ --with-stream_realip_module \ --with-stream_ssl_preread_module \ --with-http_ssl_module \ --with-mail_ssl_module \ --with-stream_ssl_module \ --with-openssl=objs/lib/openssl \ --with-openssl-opt='no-asm no-tests -D_WIN32_WINNT=0x0501' \ --with-pcre=objs/lib/pcre2 \ --with-zlib=objs/lib/zlib \ --add-module=objs/lib/nginx-rtmp-module 运行后,得到如下输出,代表着 makefile 已经生成完毕 Configuration summary + using PCRE2 library: objs/lib/pcre2 + using OpenSSL library: objs/lib/openssl + using zlib library: objs/lib/zlib nginx path prefix: "" nginx binary file: "/nginx.exe" nginx modules path: "/modules" nginx configuration prefix: "/conf" nginx configuration file: "/conf/nginx.conf" nginx pid file: "/logs/nginx.pid" nginx error log file: "/logs/error.log" nginx http access log file: "/logs/access.log" nginx http client request body temporary files: "temp/client_body_temp" nginx http proxy temporary files: "temp/proxy_temp" nginx http fastcgi temporary files: "temp/fastcgi_temp" nginx http uwsgi temporary files: "temp/uwsgi_temp" nginx http scgi temporary files: "temp/scgi_temp" 生成后,手动修改makefile,使得 msvc 编译器不将 warnings 视为错误,因为我在编译 rtmp-module 的时候报了 warnings 导致编译失败。同时添加 -MP 选项使得 msvc 支持多进程编译,加快编译速度。 输入以下指令,编辑Makefile,Makefile的具体地址请以上面的 auto\configure 脚本生成的地址为准,不同环境生成地址可能不同。 vim ./objs.msvc8/Makefile 找到CFLAGS参数,删除 -WX , 并添加 -MP ,然后保存。 以下是我修改后的参数: CFLAGS = -MP -O2 -W4 -nologo -MT -Zi -Fdobjs.msvc8/nginx.pdb -DFD_SETSIZE=1024 -DNO_SYS_TYPES_H 接下来打开 Visual Studio 2022 Developer Command Prompt , Visual Studio 版本不同,命令行名字可能也不同 切换到源码目录,运行 nmake ,等待一段时间,出现下列输出,即表示编译成功。 Finished searching libraries sed -e "s|%PREFIX%||" -e "s|%PID_PATH%|/logs/nginx.pid|" -e "s|%CONF_PATH%|/conf/nginx.conf|" -e "s|%ERROR_LOG_PATH%|/logs/error.log|" docs/man/nginx.8 objs.msvc8/nginx.8 切换到 objs.msvc8 目录运行 ./nginx -V ,在 configure arguments: 的输出中如果能看到 --add-module=objs/lib/nginx-rtmp-module ,表示 nginx 已成果添加 rtmp-module 。 End 其他 nginx-module 的编译方式类同。以上仅供参考, build toolchain 版本的不同,上述编译步骤都可能略有不同,具体请根据自身开发环境进行调整。 Reference Tags · openssl/openssl (github.com) Tags · PCRE2Project/pcre2 (github.com) Tags · madler/zlib (github.com) Building nginx on the Win32 platform with Visual C Building nginx from Sources (nginx.org) /MP(使用多个进程生成) | Microsoft LearnForeword
Linux为当前nginx添加rtmp模块非常的方便,sudo ./configure --add-module + sudo make就完事儿了,但是windows比较复杂,没有包管理器,所以各个模块的源码要自己找,下面是我在windows11下的nginx with rtmp module的编译记录。
编译器工具链有msvc toolchain、perl。
以下是我操作系统的具体信息:
Prerequisite
首先下载Nginx的源码,可以使用git也可以使用Mercurial不过因为后续要借用git bash生成makefile所以下面统一使用git。在写这篇博客时,nginx的mainline为1.25.4,所以下面编译我也用1.25.4的版本。
首先在自定义目录(自己想把源码放哪儿就在哪儿打开)打开git-bash
输入下列指令clone nginx仓库
clone 完成后,要查看一下当前版本所需依赖的版本,输入下列命令查看
我的控制台输出如下,大概可以看到openssl的版本是3.0.13,zlib的版本是1.3.1,pcre2的版本是10.39
以下我下载指定版本的依赖源码使用的是git clone,当然也可以通过下载压缩包然后解压的方式,这里我给出两种方法所需要的操作步骤
然后接着下载rtmp module的源码
Main
源码部分的准备已经完成,下面正式开始编译部分,我们重新回到源代码主目录,运行configuration script,脚本的具体配置可以参考nginx官网
但如果想要更完整的nginx,即仅仅只是在发行版上增加rtmp module,最好的办法是先看看发行版的编译参数
下载1.25.4版本,并输入nginx -V,可以看到以下参数
我们根据我们现有的库的位置,修改脚本参数
运行后,得到如下输出,代表着makefile已经生成完毕
生成后,手动修改makefile,使得msvc编译器不将warnings视为错误,因为我在编译rtmp-module的时候报了warnings导致编译失败。同时添加-MP选项使得msvc支持多进程编译,加快编译速度。
输入以下指令,编辑Makefile,Makefile的具体地址请以上面的autoconfigure 脚本生成的地址为准,不同环境生成地址可能不同。
找到CFLAGS参数,删除-WX, 并添加-MP,然后保存。
以下是我修改后的参数:
接下来打开Visual Studio 2022 Developer Command Prompt,Visual Studio 版本不同,命令行名字可能也不同
切换到源码目录,运行nmake,等待一段时间,出现下列输出,即表示编译成功。
切换到objs.msvc8目录运行./nginx -V,在configure arguments:的输出中如果能看到--add-module=objs/lib/nginx-rtmp-module,表示nginx已成果添加rtmp-module。
End
其他nginx-module的编译方式类同。以上仅供参考,build toolchain版本的不同,上述编译步骤都可能略有不同,具体请根据自身开发环境进行调整。
Reference
本文采用 CC BY-NC-SA 4.0 协议进行授权,如无注明均为原创,转载请注明出处。
标题:windows下nginx-rtmp-module的编译方法作者:九仞之行链接:http://dev.styunlen.cn/archives/post-1662.html



还没有评论呢 ~ 快来抢沙发吧 🛋️