Technology Sharing

Nginx source code compiled under Windows

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

refer to:Nginx compile and install under Windows_window How to compile and install nginx-CSDN blog

refer to:

Building nginx on the Win32 platform with Visual C

1. Install MSYS2

refer toMSYS2Download the installation content and install it.

2. Download dependent libraries:

PCRE:Download PCRE

 ZLIB: zlib Home Site

OPENSSL:[ Downloads ] - /source/index.html

3. Create an objs folder in the root directory of the nginx source code, and then create lib under objs

4. Unzip pcre-8.45.tar.gz, zlib-1.3.1.tar.gz, openssl-3.3.1.tar.gz to the lib directory. You can manually unzip them to this directory.

5. Open the installed msys2 msys and enter the nginx root directory:

cd  D:wfworknginx-1.26.1nginx-1.26.1

6.

Enter the following configuration command and press Enter: (Note that the pcre, zlib, and openssl versions must be consistent with yours)

 ./configure  --with-pcre=objs/lib/pcre-8.45  --with-zlib=objs/lib/zlib-1.3.1  --with-openssl=objs/lib/openssl-3.3.1  --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-openssl-opt=no-asm
    --with-http_ssl_module

There will be an error at the beginning:

You need to modify the version number of auto/cc/msvc NGX_MSVC_VER=19.20,

7. Open auto/cc/msvc in the root directory of nginx and find that there is no NGX_MSVC_VER version number. Since mine is vs2019, I write 19.20

The corresponding vs version numbers can be found as follows:

Fill in the version number according to your actual vs version. Only when it is filled in successfully can nmake compile successfully.

Re-run the configuration command in step 6 and complete it as follows:

You can see that the makefile file has been generated under objs in the root directory:

8. Open the VS command line window as an administrator. Since all the dependencies I downloaded above are 64-bit, I opened a 64-bit command window:

Enter the nginx root directory, enter the following command and press Enter to start compiling:

nmake -f objs/Makefile

Wait a few minutes for the compilation to complete and a sed error may pop up. Just ignore it.

At this point, nginx.exe has been generated in the objs directory, indicating that the compilation has been successful.