背景介绍

Nginx 有Windows下打包好的版本,但是在做SNI代理的时候,缺少了stream_ssl_preread_module模块。所以需要重新编译Nginx。

准备工作

工具下载

Visual Studio 2015以上版本都可以。MSYS – 默认安装就可以。 – 安装完成后,双击打开bin/mingw-get.exe 如下图步骤,依次勾选 mingw-devloper-toolkit / mingw32-base / mingw32-gcc-g++ / msys-base – 如下图,点击”Apply Changes“进行安装 Mercurial – 默认安装就可以Strawberry Perl – 默认安装就可以

Nginx 依赖包下载

openssl-1.1.1spcre2-10.35zlib-1.2.13这里下载的都是tar.gz的格式,这个格式可以用7-Zip进行解压

Nginx 源码包

打开cmd窗口,执行下面的命令,获取Nginx源码包

# 下载的文件存放在cmd界面中的目录位置下。

# 整理默认获取最新的源码包

hg clone http://hg.nginx.org/nginx

编译目录准备

在Nginx目录下,创建build目录。这个目录存放编译的相关文件和目录。在build目录下,创建lib目录。将Nginx依赖包解压后放置到这个目录下。 这个windows设备是64位的,所以在创建MakeFile前,要将Openssl模块的配置修改为x64。可以在cmd窗口中执行

# 这两句命令 到nginx/build/lib/openssl-1.0.1s目录下,找到INSTALL.W64文件,用编辑器打开后,就可以看到

perl Configure VC-WIN64A

ms\do_win64a

编译Nginx

创建MakeFile文件

打开VS2017命令行x86 Native Tools Command Prompt for VS 2017 打开的命令行界面中启动msys.bat,如下图 打开的MINGW32界面中,由于它是模拟linux环境的,所以刚进入的目录是/home/下的。要需要通过cd命令,然后进入到Nginx目录下。 在这个界面中可以按照下面的内容进行编译,也可以按照各自的需求添加删除模块

auto/configure \

--with-cc=cl \

--builddir=build \

--with-debug \

--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/pcre2-10.35 \

--with-zlib=build/lib/zlib-1.2.13 \

--with-http_v2_module \

--with-http_realip_module \

--with-http_addition_module \

--with-http_sub_module \

--with-http_dav_module \

--with-http_stub_status_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-stream \

--with-openssl=build/lib/openssl-1.1.1s \

--with-openssl-opt='no-asm no-tests -D_WIN32_WINNT=0x0501' \

--with-http_ssl_module \

--with-mail_ssl_module \

--with-stream_ssl_module \

--with-stream_ssl_preread_module

编译完成后,在build目录下就会产生许多文件,Makefile文件也在其中。

编译

我们切换到x86 Native Tools Command Prompt for VS 2017界面中cd到Nginx目录下。切记:这是是Nginx目录,不是build目录。执行下面的命令,完成编译。

nmake -f build/Makefile

编译完成后,会在bulid目录下产生nginx.exe文件

创建整体Nginx

重新创建个文件目录,取名nginx将nginx.exe拷贝到这个目录下,同时将nginx源码包中的目录(conf,contrib,docs也拷贝到这个目录下)创建temp,logs,html目录

参考阅读

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: