一、准备
首先得下载安装msys2(具体可以参考博文《windows下使用msys2编译FFmepg源码》)。
下载nginx源码,链接:http://hg.nginx.org/

下载nginx-http-flv-module,链接:https://github.com/winshining/nginx-http-flv-module
下载pcre,链接:https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz。注意,这里如果下载最新版本的pcre可能编译会报错。所以下载8.43版本的。
下载zlib,链接:http://zlib.net/

下载openssl,链接:https://www.openssl.org/source

二、编译nginx
在msys安装目录下新建文件夹SourceCode,将下载下来的nginx源码拷贝并解压到该目录中。

在nginx源码目录中新建目录objs\lib,将nginx-http-flv-module、openssl、pcre、zlib拷贝到该目录中并解压。

在nginx-f2ff291bbdac目录中创建目录logs、temp\client_body_temp、temp\proxy_temp、temp\fastcgi_temp、temp\scgi_temp。
运行msys2_shell.cmd,进入nginx-f2ff291bbdac目录,执行命令:
auto/configure --with-cc=cl --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.43 --with-zlib=objs/lib/zlib-1.2.11 --with-openssl=objs/lib/openssl-3.0.0-alpha15 --with-openssl-opt=no-asm --with-select_module --with-http_ssl_module --with-http_sub_module --with-http_v2_module --add-module=objs/lib/nginx-http-flv-module-master

如果提示:auto/cc/msvc: line 117: [: : integer expression expected。在auto/cc/msvc文件中,在下面的这个位置中添加NGX_MSVC_VER=19.11,再重新configure。

以管理员身份运行vs2015开发人员命令提示,执行命令:
nmake -f objs/Makefile
编译可能会出现error:警告被视为错误 - 没有生成“object”文件。

打开nginx源码目录的objs目录下的Makefile

将第三行CFLAGS = -O2 -W4 -WX -nologo -MT -Zi -Fdobjs/nginx.pdb -DFD_SETSIZE=1024 -DNO_SYS_TYPES_H
改为:CFLAGS = -O2 -W3 -nologo -MT -Zi -Fdobjs/nginx.pdb -DFD_SETSIZE=1024 -DNO_SYS_TYPES_H
重新编译,然后最后可能会出现提示信息:'sed' 不是内部或外部命令,也不是可运行的程序。不用管这个提示。在nginx-f2ff291bbdac\objs目录下生成了nginx.exe,表示编译成功了。

三、参考文章
《Nginx Windows下编译和安装》
|