chore: updated nignx build on Windows

This commit is contained in:
TaurusXin 2024-03-10 12:01:05 +08:00
parent a0b97c46d9
commit ee2e0f422a
Signed by: taurusxin
GPG Key ID: C334DCA04AC2D2CC

View File

@ -8,6 +8,7 @@ date: "2021-06-16 23:56:00"
---
## 前言
Nginx 在 Windows 下还是很实用的,可以作为前端的 HTTP 部署测试工具,或者当然可以用 Python 自带的 http.server 来部署,都挺快的。除了部署前端项目之外,放一些自制的基于 Web 的小工具都是极好的。
## 下载源码包
@ -16,7 +17,7 @@ Nginx 在 Windows 下还是很实用的,可以作为前端的 HTTP 部署测
Nginx 在 Windows 下编译的源码与 Linux 下的不同,直接从官网的 download 里面下载是编译不过的,需要从下面的 Mercurial 链接下载Mercurial 也是一种类似于 Git 的版本管理工具
下载地址: http://hg.nginx.org/nginx
下载地址: <http://hg.nginx.org/nginx>
注意,请选择一个带有 RELEASE TAG 的版本进行下载,如下图橙色方框所示
@ -44,15 +45,15 @@ Nginx 在 Windows 下编译的源码与 Linux 下的不同,直接从官网的
因为需要编译 OpenSSL 需要使用 perl 进行配置
https://strawberryperl.com/
<https://strawberryperl.com/>
### MSYS 2
msys2 在编译阶段仅用作配置 Makefile因本文介绍的是在 MSVC 环境下的编译,所以不用 msys2 的 GNU 环境进行编译。
下载地址https://www.msys2.org/
下载地址:<https://www.msys2.org/>
** Tip Git 的 Bash 环境也可以用作后面开始编译的配置 Makefile**
**Tip Git 的 Bash 环境也可以用作后面开始编译的配置 Makefile**
## 开始编译
@ -112,9 +113,7 @@ auto/configure \
**请提前自行创建目录 `logs``temp\client_body_temp``temp\proxy_temp``temp\fastcgi_temp``temp\scgi_temp`,否则执行脚本会提示目录不存在**
若脚本执行如果提示
> auto/cc/msvc: line 117: [: : integer expression expected
若脚本执行如果提示 `auto/cc/msvc: line 117: [: : integer expression expected`
是因为读取不到 VC 编译器的版本,需要手动指定。
@ -122,7 +121,7 @@ auto/configure \
![编译器版本][7]
打开 auto/cc/msvc 文件,在文件的 `NGX_MSVC_VER=...` 下方添加如下代码,即手动指定 MSVC 编译器的版本(采用截图原因是方便定位添加代码的位置)
打开 `auto/cc/msvc` 文件,在文件的 `NGX_MSVC_VER=...` 下方添加如下代码,即手动指定 MSVC 编译器的版本(采用截图原因是方便定位添加代码的位置)
![手动指定 MSVC 版本][8]
@ -136,9 +135,9 @@ auto/configure \
cd 到源码根目录后,执行编译命令
> nmake f objs/Makefile
```shell
nmake f objs/Makefile
```
编译过程较久,视 CPU 单核性能而定,耗时十分钟到半小时不等。
@ -147,29 +146,34 @@ cd 到源码根目录后,执行编译命令
没有其它报错退出时, Nginx 即编译完成。
## 整理文件
将源码目录下的`conf``contrib` `html` `logs` `temp``objs\nginx.exe` 整理到一个目录下,双击打开 nginx.exe命令行一闪而过打开浏览器输入 http://localhost/ 或 http://127.0.0.1/ 看到以下页面即成功。
将源码目录下的`conf``contrib` `html` `logs` `temp``objs\nginx.exe` 整理到一个目录下,双击打开 nginx.exe命令行一闪而过打开浏览器输入 `http://localhost/``http://127.0.0.1/` 看到以下页面即成功。
![success.png][10]
输入以下命令结束运行 Nginx
`nginx.exe -s stop`
```shell
nginx.exe -s stop
```
## 笔者编译的版本
版本1.21.4
版本信息:
```shell
nginx version: nginx/1.21.4
built by cl 19.30.30706
built with OpenSSL 3.0.0 7 sep 2021
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=1024 --with-pcre=objs/pcre-8.45 --with-zlib=objs/zlib-1.2.11 --with-openssl=objs/openssl-3.0.0 --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
```
> nginx version: nginx/1.21.4
> built by cl 19.30.30706
> built with OpenSSL 3.0.0 7 sep 2021
> 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=1024 --with-pcre=objs/pcre-8.45 --with-zlib=objs/zlib-1.2.11 --with-openssl=objs/openssl-3.0.0 --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
下载地址:[button color="light" icon="" url="https://cdn.rhyland.cn/typecho/2021/12/06/nginx-1.21.4.zip" type=""]下载[/button]
下载地址:[点击这里](https://cdn.rhyland.cn/typecho/2021/12/06/nginx-1.21.4.zip)
## 结语
至此Nginx 在 Windows 10 下,使用 MSVC 2019 的完整编译过程结束,任何报错,不明白请在下方评论区留言!
[1]: https://cdn.rhyland.cn/typecho/2021/06/14/download.png