Windows 源码编译 nginx (加入nginx-http-flv-module)

文章目录

    • windows 源码编译 nginx,可以加入功能模块
      • 1. 依赖
      • 2. 步骤
        • 2.1 下载源码
        • 2.2 解压依赖
        • 2.3 配置环境变量
        • 2.4 配置和编译
      • 3. 测试
      • 4. 参考

windows 源码编译 nginx,可以加入功能模块

1. 依赖

  • Strawberry Perl:配置环境变量,参考后文2.3节
  • GnuWin32-sed:配置环境变量,参考后文2.3节
  • OpenSSL-Win32:配置环境变量,参考后文2.3节,这个和下面的依赖的openssl不太一样,这个是可执行源文件,下面是源代码,下面的是nginx编译时需要依赖的源文件
  • PCRE, zlib and OpenSSL libraries sources:设置编译依赖
  • nmake:编译工具,一般在VS中都有,设置环境变量就可以,我的是VS2017,路径是 C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\nmake.exe
  • rc.exe:编译工具,一般在 Windows Kits 中,我的路径是C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86\rc.exe

如果参考 nginx 官网文档的话还需要 MSYS 和 Mercurial client,但是我编译时候没用,后文附官方文档链接

2. 步骤

2.1 下载源码

直接去 http://hg.nginx.org/nginx 上下载源码,解压之后的文件目录结构是:

Windows 源码编译 nginx (加入nginx-http-flv-module)_第1张图片

2.2 解压依赖

在解压的文件夹中新建 objs\lib 文件夹,然后将上面下载的依赖 openssl zlib PCRE 三个依赖以及你自己想要编译的模块比如我的是 nginx-http-flv-module 解压之后放到 objs\lib 文件夹中,如下:

Windows 源码编译 nginx (加入nginx-http-flv-module)_第2张图片

2.3 配置环境变量

  • 设置 Strawberry Perl GnuWin32-sed 环境变量
    perl sed
  • OpenSSL-Win32
    openssl-win32
  • nmake
    nmake
  • rc.exe
    rc

2.4 配置和编译

  • configure:回到 nignx 主目录,(其中的prefix路径可以稍微改改,但是最好不要改,windows路径和linux不太一样
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/pcre2-10.40 \
    --with-zlib=objs/lib/zlib-1.2.13 \
    --with-openssl=objs/lib/openssl-1.1.1s \
    --with-openssl-opt=no-asm \
    --with-http_ssl_module \
    --add-module=objs/lib/nginx-http-flv-module
  • make:回到 nignx 主目录
nmake -f objs\Makefile

如果出现比如rc'不是内部或外部命令,也不是可运行的程序'等错误就是环境变量没配好

3. 测试

编译成功之后会在objs文件夹下出现nginx.exe可执行文件
nginx-V
另外运行nginx.exe出现创建文件失败错误的话,比如[alert] could not open error log file: CreateFile和 [emerg] 10888#16720: CreateDirectory()
只需要在nginx主目录下创建相应的文件夹,比如常见的文件有 temp logs

4. 参考

  • http://nginx.org/en/docs/howto_build_on_win32.html
  • https://www.dapan.cc/article/2022/11/18841/

你可能感兴趣的:(Miscellaneous,windows,nginx,http,nginx-http-flv)