Windows下利用MSYS2和VS的nmake编译nginx源码

news2024/9/21 9:16:39

目录

一、使用说明

二、安装软件

2.1 下载依赖库

2.3 下载并安装 StrawberryPerl

2.4 下载并安装 MSYS 2

2.5 nginx源代码下载 

三、编译配置

3.1 设置NGX_MSVC_VER

3.2 配置 Makefile

3.3 编译代码

3.4 整理Nginx发布环境

四、错误处理


一、使用说明

本文章主要记录Windows下利用MSYS2和VS的nmake编译nginx源码。

这是Nginx官方说明 https://nginx.org/en/docs/howto_build_on_win32.html

To build nginx on the Microsoft Win32® platform you need:

  • Microsoft Visual C compiler. Microsoft Visual Studio® 8 and 10 are known to work.
  • MSYS or MSYS2.
  • Perl, if you want to build OpenSSL® and nginx with SSL support. For example ActivePerl or Strawberry Perl.
  • Git client.
  • PCRE, zlib and OpenSSL libraries sources.

需要安装软件Visual Studio 2022 (一定要包含C++ x64/x86 生成工具,需要通过nmake执行编译)

Openssl:实现安全套接字ssl功能

Pcre:实现正则表达式解析

Zlib:实现gzip压缩解压缩功能

二、安装软件
2.1 下载依赖库

zlib源代码下载

https://zlib.net/ 

PCRE源代码  

https://sourceforge.net/projects/pcre/files/pcre/

openssl源代码下载 https://github.com/openssl/openssl/releases/tag/openssl-3.3.2

2.3 下载并安装 StrawberryPerl

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

下载地址: https://strawberryperl.com/

默认安装到结束

2.4 下载并安装 MSYS 2

在编译阶段用作配置 Makefile  下载地址:https://www.msys2.org/

全部默认安装

2.5 nginx源代码下载 

地址 https://hg.nginx.org/nginx

点左侧ZIP进行下载

将文件解压,在nginx源码根目录下创建objs文件夹,再在objs下创建lib文件夹,结构如下图

将pcre-8.45.zip、zlib131.zip、openssl-openssl-3.3.2.zip解压到刚刚的lib目录

三、编译配置
3.1 设置NGX_MSVC_VER

如果不指定版本会在配置时出现报错auto/cc/msvc: line 132: [: : integer expression expected

需要根据你自己的实际vs版本号填写,只有填写成功,后面nmake才能编译成功。修改nginx\auto\cc下的msvc文件,指定NGX_MSVC_VER版本号,我vs是2022,所以是1930

3.2 配置 Makefile

使用 msys2 的任意环境进入 nginx 源码目录

从开始菜单打开安装的msys2 msys

进入到nginx源码根目录下

cd /c/sourcecode/nginx

 执行以下命令,用于生成适用于 MSVC 的 Makefile

输入如下配置命令后回车:(注意pcre,zlib,openssl版本要与你实际的文件夹一致)

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=32768 \
  --with-pcre=objs/lib/pcre-8.45 \
  --with-zlib=objs/lib/zlib-1.3.1 \
  --with-openssl=objs/lib/openssl-3.3.2 \
  --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

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

Administrator@DESKTOP-0JFTJUC MSYS /c/sourcecode/nginx
# 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=32768 \
  --with-pcre=objs/lib/pcre-8.45 \
  --with-zlib=objs/lib/zlib-1.3.1 \
  --with-openssl=objs/lib/openssl-3.3.2 \
  --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
checking for OS
 + MSYS_NT-10.0-19045 3.5.3-d8b21b8c.x86_64 x86_64
 + using Microsoft Visual C++ compiler
 + cl version: 1930
checking for MSYS_NT-10.0-19045 specific features
creating objs/Makefile

Configuration summary
  + using PCRE library: objs/lib/pcre-8.45
  + using OpenSSL library: objs/lib/openssl-3.3.2
  + using zlib library: objs/lib/zlib-1.3.1

  nginx path prefix: ""
  nginx binary file: "/nginx.exe"
  nginx modules path: "/modules"
  nginx configuration prefix: "/conf"
  nginx configuration file: "/conf/nginx.conf"
  nginx pid file: "/logs/nginx.pid"
  nginx error log file: "/logs/error.log"
  nginx http access log file: "/logs/access.log"
  nginx http client request body temporary files: "temp/client_body_temp"
  nginx http proxy temporary files: "temp/proxy_temp"
  nginx http fastcgi temporary files: "temp/fastcgi_temp"
  nginx http uwsgi temporary files: "temp/uwsgi_temp"
  nginx http scgi temporary files: "temp/scgi_temp"


Administrator@DESKTOP-0JFTJUC MSYS /c/sourcecode/nginx

可以看到根目录下的objs下已经生成了makefile文件

3.3 编译代码

以管理员方式打开VS对应的 X64 Native Tools Command … for VS 2022

进入到nginx根目录,输入如下命令后回车

nmake -f objs/Makefile

 就开始编译

等待编译完成,会在 nginx/objs/ 文件夹内出现 nginx.exe

至此,Nginx编译完成。打开objs目录,显示如下

3.4 整理Nginx发布环境

nginx.exe运行依赖同级目录下存在conf、html、logs、temp目录及配置文件,否则无法启动。将源码目录下的conf、contrib、html、logs、temp和objs\nginx.exe整理到一个目录下。

启动nginx.exe,一个nginx服务器就搭建起来了,运行截图  

看生成的nginx编译信息  nginx -V

C:\nginx>nginx -V
nginx version: nginx/1.27.2
built by cl 1930
built with OpenSSL 3.3.2 3 Sep 2024
TLS SNI support enabled
configure arguments: --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=32768 --with-pcre=objs/lib/pcre-8.45 --with-zlib=objs/lib/zlib-1.3.1 --with-openssl=objs/lib/openssl-3.3.2 --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
四、错误处理

4.1 auto/cc/msvc: line 132: [: : integer expression expected

这里报错原因是msvc版本缺失,无法自动识别,根据3.1章节进行设置

4.2 找不到VS带的X64 Native Tools Command … for VS xxxx

检查VS安装是否包含了C++ x64/x86 生成工具。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2151930.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Hash入门

unordered_set void test_unordered_set() {unordered_set<int> us;us.insert(4);us.insert(2);us.insert(1);us.insert(5);us.insert(6);us.insert(2);us.insert(2);//去重unordered_set<int>::iterator it us.begin();while (it ! us.end()){cout << *it…

​OpenAI最强模型o1系列:开启人工智能推理新时代

前不久OpenAI发布全新模型——o1模型&#xff0c;也就是业界说的“草莓模型”&#xff0c;包含三款型号&#xff1a;OpenAI o1、OpenAI o1-preview和OpenAI o1-mini。 其中&#xff0c;OpenAI o1-mini和 o1-preview已经对用户开放使用&#xff1a; OpenAI o1&#xff1a;高级推…

mysql笔记—sql性能分析

1.查看数据库各个语句的执行频次 show global/session status like ‘com__’ 2.慢查询 默认没有开启&#xff0c;需要手动开启&#xff08;在/etc/my.cnf中开启&#xff09; 开启后在localhost-slow.log中可以查询到慢查询的语句的相关信息&#xff1a; 3.explain 用法&…

<<编码>> 第 16 章 存储器组织(1)--比特锁存器 示例电路

1 比特锁存器 info::操作说明 鼠标单击逻辑输入切换 0|1 状态 就是前面的电平触发的 D 型锁存器. 写入(Write) 就是时钟信号 primary::在线交互操作链接 https://cc.xiaogd.net/?startCircuitLinkhttps://book.xiaogd.net/code-hlchs-examples/assets/circuit/code-hlchs-ch16…

2025年最新大数据毕业设计选题-Hadoop综合项目

选题思路 回忆学过的知识(Python、Java、Hadoop、Hive、Sqoop、Spark、算法等等。。。) 结合学过的知识确定大的方向 a. 确定技术方向&#xff0c;比如基于Hadoop、基于Hive、基于Spark 等等。。。 b. 确定业务方向&#xff0c;比如民宿分析、电商行为分析、天气分析等等。。。…

OpenCV特征检测(6)对初步检测到的角点位置进行亚像素级别的精炼函数cornerSubPix()的使用

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 细化角点的位置。 该函数迭代以找到角点或径向鞍点的亚像素级准确位置&#xff0c;如 93中所述&#xff0c;并如下图所示。 亚像素级准确的角点…

TryHackMe 第2天 | Pre Security (上)

该学习路径讲解了网络安全入门的必备技术知识&#xff0c;比如计算机网络、网络协议、Linux命令、Windows设置等内容。本篇博客将记录第一项&#xff1a;计算机网络。 Network Fundamentals What is networking? 网络就是相互连接的事物&#xff0c;我们的人际关系也可以抽…

Liveweb视频汇聚平台支持GB28181转RTMP、HLS、RTSP、FLV格式播放方案

GB28181协议凭借其在安防流媒体行业独有的大统一地位&#xff0c;目前已经在各种安防项目上使用。雪亮工程、幼儿园监控、智慧工地、物流监控等等项目上目前都需要接入安防摄像头或平台进行直播、回放。而GB28181协议作为国家推荐标准&#xff0c;目前基本所有厂家的安防摄像头…

[Unity Demo]从零开始制作空洞骑士Hollow Knight第六集:制作小骑士完整的跳跃落地行为

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、制作一个完整的小骑士跳跃落地行为 1.制作动画以及UNITY编辑器编辑2.使用代码实现完整的跳跃落地行为控制3.更多要考虑到的点总结 前言 大家好久不见&…

【CSS Tricks】如何做一个粒子效果的logo

效果展示 代码展示 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta name"viewport" content"widthdevice-width, initial-scale1.0" /><title>粒子效果Logo</title>…

VUE面试题(单页应用及其首屏加载速度慢的问题)

目录 一、单页应用 1.概念 2.单页面应用的优缺点 二、多页面应用&#xff1a; 1.概念 2.区别 三、SPA的实现 1.原理 2.方式&#xff1a; 3.Hash与History模式有什么区别 四、首屏加载速度慢如何优化 1.什么是首屏加载&#xff1f; 2.首屏加载慢的原因 3.如何解决…

OpenCV特征检测(2)边缘检测函数Canny()的使用

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 使用 Canny 算法 48在图像中查找边缘。 该函数使用 Canny 算法在输入图像中查找边缘&#xff0c;并在输出地图 edges 中标记它们。在 threshold1…

【0332】Postgres内核 start background worker(s)

0. 相关联文件 postmaster.cilist.h1. 启动 background worker(s) Postgres内核在 PostmasterMain() 函数中初始化 postmaster 守护进程时候,通过 maybe_start_bgworkers() 函数开始尝试启动 background worker(s)。 若时机恰当,则启动 background worker(s)。 作为一种附带…

基于云的补丁管理

什么是云补丁 云补丁或基于云的补丁管理是指扫描和检测缺失补丁、测试补丁并将它们部署到所需系统的过程&#xff0c;所有这些都通过基于云的控制台或软件完成。虽然补丁管理工作流程通常保持不变&#xff0c;但基于云的补丁管理的主要区别在于&#xff0c;整个过程仅通过基于…

iOS 18 适配 Xcode 16 问题

在适配 iOS 18 xcode 16时遇到的问题&#xff0c;记录一下。 1. 使用xcode 16 iOS 18 运行App时遇到&#xff0c;APP 的icon 出现空白现象。 原先APP icon 设置方案。 暂时解决方案&#xff1a; 2、

Python 低层多线程接口_thread的用法

_thread是python标准库中的一个低层多线程API&#xff0c;可以在进程中启动线程来处理任务&#xff0c;并且提供了简单的锁机制来控制共享资源的同步访问。本文就_thread模块的用法和特性做个简单的演示。 文章目录 一、进程和线程的区别二、_thread模块的用法2.1 派生线程2.2…

Percona发布开源DBaaS平台;阿里云RDS发布全球多活数据库(GAD);Redshift支持自然语言生成SQL

重要更新 1. 云栖大会于本周四/五在杭州举行&#xff0c;周五上午云栖主论坛阿里云数据库负责人李飞飞将发表《从数据到智能&#xff1a;DataAI驱动的云原生数据库》演讲&#xff0c;另外&#xff0c;还有多场次的数据库专场&#xff0c;感兴趣的可以现场或在线观看&#xff1a…

个人小结(2.0)

离谱&#xff0c;困扰着几周的问题今天偶然发现了解决方法。 问题如下&#xff1a;就是对应的模块引入爆红&#xff0c;但是单击进入引入的文件没有问题 然后它的提示是&#xff1a; 无法找到模块“../views/screen/index.vue”的声明文件。“c:/Users/10834/Desktop/0716_pro…

vue-使用refs取值,打印出来是个数组??

背景&#xff1a; 经常使用$refs去获取组件实例&#xff0c;一般都是拿到实例对象&#xff0c;这次去取值的时候发现&#xff0c;拿到的竟然是个数组。 原因&#xff1a; 这是vue的特性,自动把v-for里面的ref展开成数组的形式&#xff0c;哪怕你的ref名字是唯一的&#xff01…

DataX--Web:图形化界面简化大数据任务管理

在处理大数据任务时&#xff0c;频繁地修改配置文件或编写脚本可能会变得繁琐且容易出错。DataX Web提供了一个图形化界面&#xff0c;旨在简化这些操作&#xff0c;让用户通过直观的界面管理数据同步任务。 DataX Web简介 DataX Web是一个开源项目&#xff0c;它允许用户通过…