- 一、准备
- 二、下载nginx源代码
- 三、添加依赖
- 四、生成Makefile
- 五、处理一些小问题
- 六、编译
- 七、执行前准备
系统环境:vs2019 buildtools
发布时间:2022.4,注意时效性 一、准备
由于要编译64位nginx,以下所有软件均使用64位
- git for windows (用msys2也行)
- strawberryperl 下载链接
- nasm 下载链接,解压后把所有可执行文件放在一个目录里,把这个目录加入PATH
- sed 下载链接,安装后把安装目录加入PATH
- 下载依赖库:pcre,zlib,openssl, ngx-fancyindex,注意:千万不要下载pcre2!
看网上有人先下载安装Mercurial再下载源代码,但完全可以直接下载,进入链接,点击最上边的那个release,然后点击最左边的zip,我下的是stable-1.20.zip
在nginx源代码分别创建 objslib 文件夹,并且将下载好的ngx-fancyindex、openssl、pcre、zlib分别解压在lib文件夹下面
结果如下图:
四、生成Makefile使用git bash,进入nginx根文件夹,执行
auto/configure --with-cc=cl --builddir=objs --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.45 --with-zlib=objs/lib/zlib-1.2.11 --with-openssl=objs/lib/openssl-1.1.1n --with-select_module --with-http_ssl_module --add-module=objs/lib/ngx-fancyindex-0.5.2
如果有依赖库版本不一样的时候,注意更改
修改 nginxautolibopensslmakefile.msvc 文件,将9行VC-WIN32改为VC-WIN64A,将15行msdo_ms 改为 msdo_nasm
修改 autoccmsvc 文件,将83行-W4改为-W3,并将117和119行注释掉
打开x64提示符,进入nginx根文件夹,执行nmake -f Makefile
等待一段时间后即可编译成功
将根目录中的conf、contrib、docs、misc文件夹复制到新文件夹,将objs/nginx.exe复制到该文件夹根目录下,新建temp、html文件夹
如图:
开启目录索引:编辑 conf/nginx.conf
location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
charset utf-8; # 如果中文有乱码,可配置为:gbk,utf-8
fancyindex on; # 启用插件
fancyindex_localtime on; # 使用本地时间
fancyindex_exact_size off; # 是否使用精确的大小,on显示字节,off显示如 M 这种
fancyindex_footer "/fancy-theme/footer.html"; # 主题页脚文件
fancyindex_header "/fancy-theme/header.html"; # 主题头部文件
fancyindex_ignore "example.html"; # 忽略显示的文件名称
fancyindex_ignore "fancy-theme"; # 忽略显示的目录
fancyindex_name_length 255;
fancyindex_time_format "%Y-%m-%d %H:%M";
}
双击nginx.exe即可运行
已经编译完的nginx下载链接:
https://pan.baidu.com/s/1Kup0RgInlY7BmnHOxqibBw 提取码: vghm



