Windows环境编译nginx
准备工具
- MSYS用来修改nginx编译配置,mingw-get-setup.exe
- perl, strawberryperl
- vs命令行工具 Visual Studio C++ Build Tools
- nginx源码, nginx-1.15.10
- nginx安装库 openssl-1.0.2r, zlib-1.2.11,pcre-8.43
安装解压
1. 安装 mingw,strawberryperl,vs build tools
安装完mingw后,点击continue打开 mingw 程序 ,接下来勾选上 Basic Setup
里的 msys-base
, 然后 Apply Changes, 开始安装msys。

安装完后vs build tool后,添加环境变量
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC

2. 解压
将nginx解压到nginx文件夹下,再新建如下格式的文件夹下:
nginx
—-build
——–lib
将openssl、zlib、pcre解压到lib文件夹中。
可以用2345好压直接将tar.gz格式的压缩包解压,可以参考本文底部参考1
3. 修改nginx编译配置
安装完成msys后,进入 C:\MinGW\msys
文件夹打开msys.bat
。
cd进入nginx目录,在命令行中执行:
auto/configure --with-cc=cl \
--builddir=build \
--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=build/lib/pcre-8.43 \
--with-zlib=build/lib/zlib-1.2.11 \
--with-openssl=build/lib/openssl-1.0.2r \
--with-select_module \
--with-http_ssl_module \
--with-http_sub_module
执行完毕后,会在build文件夹下生成预编译文件。
进入nginx\auto\lib\openssl
,用编辑器打开 makefile.msvc
,修改配置保存。

编译
进入C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2015\Visual Studio Tools\Windows Desktop Command Prompts
双击VS2015 x86 Native Tools Command Prompt
然后cd进入nginx目录
。
OK, 最后一步,编译nginx,在命令行中输入: nmake -f build/Makefile
回车等待编译。
测试
运行完毕后,如果在build文件夹下看到nginx.exe, 表明已经编译成功。
把build文件夹下的nginx.exe复制到nginx目录下, 再在该目录下创建temp和logs文件夹。
在该目录下打开cmd,执行nginx -t

参考1 : https://blog.csdn.net/i348018533/article/details/51701865
666666