Compiling nginx and adding module HTTP in windows system_ gzip_ static_ module

Reference address:

http://nginx.org/en/docs/howto_build_on_win32.html

https://www.cnblogs.com/iamyuxing/p/10883626.html

I uploaded the compiled with: http on git_ gzip_ static_ Module module version 1.20.2. You can take what you need and integrate other modules. You can also take down the code and recompile it according to the article content.

https://gitee.com/lingyangcj/nginx-1.20.2-build-windows

The compressed file nginx-1.20.2 (compiled file) in the current directory zip


preparation

To build nginx on the Microsoft Win32 platform, you need to:


Build steps

Download source code

need Mercurial client:
https://www.mercurial-scm.org/release/tortoisehg/windows/tortoisehg-6.0.0-x64.msi
hg clone http://hg.nginx.org/nginx

Download and unzip the libraries on which Nginx depends

https://www.openssl.org/source/openssl-1.1.1m.tar.gz

http://zlib.net/zlib-1.2.11.tar.gz

https://udomain.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.zip

Openssl: implement secure socket ssl function

Pcre: implement regular expression parsing

Zlib: implement gzip compression and decompression function


The Perl interpreter is installed mainly to parse scripts in openssl

https://strawberryperl.com/download/5.32.1.1/strawberry-perl-5.32.1.1-32bit.msi


Create an objs directory under the root directory of the source code, create a lib folder under the objs directory, and copy the extracted openssl, pcre and zlib to the Lib directory

mkdir objs
mkdir objs/lib
cd objs/lib
tar -xzf ../../pcre-8.44.tar.gz
tar -xzf ../../zlib-1.2.11.tar.gz
tar -xzf ../../openssl-1.1.1l.tar.gz

Download and install MSYS2 (simulate unix Environment)

https://github.com/msys2/msys2-installer/releases/download/2021-11-30/msys2-x86_64-20211130.exe

Before generating Makefile, modify the msvc file in the auto\cc directory of the source code as follows:

  1. Set the optimization option for line 83 to - W3
  2. Comment out lines 117 and 119 (because I use VS2019 with a higher version, it needs to be commented out, otherwise an exception will be reported)

Open MSYS2 and switch to the decompression directory (root directory) of the Nginx source package

cd /H/Work/company_work_space/scmp-project/nginx-1.20.2

Execute the following commands. Note whether the location of the configure file is in the root directory or under auto (the root directory can be cut to auto and use the following command). Note whether the paths of pcre, zlib and openssl correspond,

with-http_gzip_static_module is additional to gzip module required by my environment. The default module does not include this module. You can add modules here to implement nginx's custom modules.

auto/configure \
--with-cc=cl \
--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=objs/lib/pcre-8.45 \
--with-zlib=objs/lib/zlib-1.2.11 \
--with-openssl=objs/lib/openssl-1.1.1m \
--with-openssl-opt=no-asm \
--with-http_ssl_module \
--with-http_gzip_static_module

The above command generates a Makefile that can be compiled through the nmake of VS

The whole compilation process is as follows (this process occurs on the MSYS2 command line):

Administrator@WIN-7ECCVP09AEC MSYS /H/Work/company_work_space/scmp-project/nginx-1.20.2
# auto/configure \
 --with-cc=cl \
 --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=objs/lib/pcre-8.45 \
 --with-zlib=objs/lib/zlib-1.2.11 \
 --with-openssl=objs/lib/openssl-1.1.1m \
 --with-openssl-opt=no-asm \
 --with-http_ssl_module \
 --with-http_gzip_static_module

checking for OS
 + MSYS_NT-10.0-17763 3.2.0-340.x86_64 x86_64
 + using Microsoft Visual C++ compiler
 + cl version:
checking for MSYS_NT-10.0-17763 specific features
creating objs/Makefile

Configuration summary
  + using PCRE library: objs/lib/pcre-8.45
  + using OpenSSL library: objs/lib/openssl-1.1.1m
  + using zlib library: objs/lib/zlib-1.2.11

  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"

You can see many lines of ngin xxx. So far, you can close MSYS2. At this time, a Makefile is generated in the root directory of the source code, and some makefiles and header files for compilation are generated in the objs folder


Run production

1.function VS command line x86 Native Tools Command Prompt for VS 2022(Visual Studio 2022 Community Edition)
2.Switch to Nginx root directory cd H:\Work\company_work_space\scmp-project\nginx-1.20.2
3.Execute the following command: nmake -f objs/Makefile
4.use VS of nmake After compiling, the objs Generated under directory exe file
5.Create a new nginx Folder for,In the source code conf,contrib,html Copy it and put it objs Generated in directory nginx.exe Put it in and create a new one logs and temp Folder, that's it nginx for windows My job.

Nginx build for windows summary:

1.Nginx is a 32-bit software, so it is best to use 32-bit MSYS2 and VS 32-bit command line to compile

2. If you want to compile on 64 bit, you need to modify the Makefile generated in openssl

3.Openssl1. For versions above 1, VC-WIN32 in Makefile needs to be changed to VC-WIN64A

4.Openssl1. The version of 0 requires a change to install W64 file find To build for Win64/x64 and execute those lines of scripts with perl.

Keywords: Windows Nginx

Added by dspeer on Mon, 10 Jan 2022 15:35:03 +0200