0
点赞
收藏
分享

微信扫一扫

两大信号 华为又有神操作

zhoulujun 2024-09-04 阅读 26

一、软件准备


1、安装 Visual Studio 2022

包含单个组件:

  • .NET Framework 4.6.1 目标包
  • .NET Framework 4.6.1 SDK
  • Windows 通用 C 运行时
  • Windows 通用 CRT SDK
  • MSVC v142 - VS 2019 C++ x64/x86 生成工具(v14.26)
  • 对 v142 生成工具(14.21)的 C++/CLI 支持
  • Clang compile for Windows
  • Windows 10 SDK (10.0.16299.0)

Visual Studio 2022 的安装这里就不再详细说明。


2、下载源码

下载地址


请选择一个带有 RELEASE TAG 的版本进行下载,如下图:

截至目前, Nginx 的最新 release 版本为 1.26.2

在这里插入图片描述


在左侧选择压缩包类型,点击下载即可,这里我选择ZIP


在这里插入图片描述


下载完成获得源码文件,解压后如下:


在这里插入图片描述


3、下载 pcre 源码包,解压至 objs/lib 文件夹

在这里插入图片描述


4、下载 zlib 源码包,解压至 objs/lib 文件夹

在这里插入图片描述


5、下载 openssl 的源码包,解压至 objs/lib 文件夹

在这里插入图片描述


6、下载并安装 StrawberryPerl

因为需要编译 OpenSSL, 需要使用 perl 进行配置

https://strawberryperl.com/


在这里插入图片描述


安装,同意协议,直接next
在这里插入图片描述


在这里插入图片描述


7、下载并安装 MSYS 2

msys2 在编译阶段用作配置 Makefile

下载地址:https://www.msys2.org/


在这里插入图片描述


安装,直接next ,直到安装完成

在这里插入图片描述


![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/98d8ca9df81f435593ab66eb92e60033.png#pic_center)

二、编译配置


1、修改 /nginx/auto/cc/msvc 文件

MSVC 2022 对应 19.34,在 echo " + cl version: $NGX_MSVC_VER" 的上一行加上 :NGX_MSVC_VER=19.34


在这里插入图片描述


在这里插入图片描述


2、64位编译修改(32位编译忽略)

  • Step 1: 打开.\auto\lib\openssl\makefile.msvc文件

在这里插入图片描述


  • Step 2: 找到以下代码进行替换

    • perl Configure $(OPENSSL_TARGET) no-shared no-threads替换为perl Configure VC-WIN64A no-shared

在这里插入图片描述


  • Step 3 找到以下代码进行替换

  • if exist ms\do_ms.bat 替换为if exist ms\do_win64a.bat

  • ms\do_ms替换为ms\do_win64a

在这里插入图片描述


3、配置 Makefile
  • Step 1: 使用 msys2 的任意环境进入 nginx 源码目录
cd D:\Nginx

在这里插入图片描述


  • Step 2: 执行以下命令,用于生成适用于 MSVC 的 Makefile

以下命令行配置了 nginx 在 Windows 下的常用模块的编译,可以根据自己需要调整相关模块:

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.45 \
  --with-zlib=objs/lib/zlib-1.3.1 \
  --with-openssl=objs/lib/openssl-3.3.1 \
  --with-openssl-opt='no-asm no-tests -D_WIN32_WINNT=0x0601' \
  --with-http_ssl_module \
  --with-http_v2_module \
  --with-http_realip_module \
  --with-http_addition_module \
  --with-http_sub_module \
  --with-http_stub_status_module \
  --with-http_dav_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-mail_ssl_module \
  --with-stream \
  --with-stream_ssl_module \
  --with-stream_ssl_preread_module


执行成功,会出现以下界面:


在这里插入图片描述


  • Step 3: 打开VS对应的 X64 Native Tools Command … for VS 2022

在这里插入图片描述


在这里插入图片描述


![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/7fc82884e1dc4a3b9b1386125f61ba79.png#pic_center)

Step 4: 切换到Nginx根目录 执行编译命令


cd /d D:\Nginx
nmake -f objs/Makefile

如下图:
在这里插入图片描述


等待编译完成,会在 nginx/objs/ 文件夹内出现 nginx.exe,如下图所示:
在这里插入图片描述


nginx.exe运行依赖同级目录下存在conf、html、logs、temp目录及配置文件,否则无法启动。


举报

相关推荐

0 条评论