Compile Nginx 64bit in Windows

Nginx is a well known webservice software, people usually use lnmp/lamp(linux nginx/apache mysql php) as Web server environment. This time I will try to make a simply index service for windows to provide download service. The Nginx has it’s basic index service named autoindex, but the layout is so bad, it didn’t provide any search service. I found a alternative index service fancyindex, it can elegant finish such work.

Prepare:

compile environment:

  • MSYS environment (or MSYS2)
  • Microsoft Visual Studio, usually requires version 2008 and above, I will use 2017 here.
  • Perl environment, it will be use to compile openssl, we can use Strawberry Perl or ActivePerl.
  • Mercurial and Git
  • nasm, ASM optimize package

nasm is optional, when nasm not exist, you have to disable assembler optimize.

get the source code:

nginx source code:

the source code for windows needs to be clone with Mercurial:

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

this step can be finished with CMD or MSYS.

other libs and additional modules:

download PCREzlib and OpenSSL, and uncompress them(following code should be run in MSYS terminal):

 

mkdir -p objs/lib
cd objs/lib
tar -xzf ../../pcre-8.42.tar.gz
tar -xzf ../../zlib-1.2.11.tar.gz
tar -xzf ../../openssl-1.0.2q.tar.gz

clone fanxyindex source code

 

git clone https://github.com/aperezdc/ngx-fancyindex.git ngx-fancyindex

Edit configuration for compiling:

Edit configuration for openssl (when you need to compile 64bit executable):

 


# Copyright (C) Igor Sysoev
# Copyright (C) Nginx, Inc.
 
 
all:
    cd $(OPENSSL)
 
    perl Configure VC-WIN64A no-shared                  \
        --prefix="%cd%/openssl"                         \
        --openssldir="%cd%/openssl/ssl"                 \
        $(OPENSSL_OPT)
 
    if exist ms\do_win64a.bat (                         \
        ms\do_win64a                                    \
        && $(MAKE) -f ms\nt.mak                         \
        && $(MAKE) -f ms\nt.mak install                 \
    ) else (                                            \
        $(MAKE)                                         \
        && $(MAKE) install_sw                           \
    )


Change warning level:

the default warning level may cause unexpected abort when compiling. So we can edit nginx\auto\cc\msvc (about line 83):

 

# warnings
 
CFLAGS="$CFLAGS -W3"

add msvc linker version:

you will see a warning if you don’t add this parameter “auto/cc/msvc: line 117: [: : integer expression expected”, this will not affect the compile (about line 17)

 

NGX_MSVC_VER=19.12 # MSVC 2017 (15.5.7)  cl 19.12
 
echo " + cl version: $NGX_MSVC_VER"

delete edit of manpage:

the Windows CMD or powershell don’t have a sed command, it may cause a error, nginx\objs\Makefile (about line 1762):

 

manpage:    objs/nginx.8
 
objs/nginx.8:   docs/man/nginx.8 objs/ngx_auto_config.h
    #sed -e "s|%%PREFIX%%||" \
        #-e "s|%%PID_PATH%%|/logs/nginx.pid|" \
        #-e "s|%%CONF_PATH%%|/conf/nginx.conf|" \
        #-e "s|%%ERROR_LOG_PATH%%|/logs/error.log|" \
        #< docs/man/nginx.8 > $@

compile:

configure:

run config with MSYS, the configuration is the same as Nginx official website with extra fancyindex module:

 

auto/configure \
--with-cc=cl \
--builddir=objs \
--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.42 \
--with-zlib=objs/lib/zlib-1.2.11 \
--with-select_module \
--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=objs/lib/openssl-1.0.2q \
--with-http_ssl_module \
--with-mail_ssl_module \
--with-stream_ssl_module \
--add-module=objs/lib/ngx-fancyindex

you should add following parameter when you don’t have nasm

 

--with-openssl-opt=no-asm

compile:

after configuration, you can compile the executable file with MSVC tool-chain:
for 64bit os, you can use 64 Native Tools Command Prompt for VS 2017, add path for nasm before compile:

 

"C:\Program Files\NASM\nasmpath.bat"

compiling:

 

nmake /f objs\MakeFile

you can have a cup of coffee now.

In the end, you can find the nginx.exe in the folder. The useage of fancyindex can be found there Link

reference:

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

https://blog.csdn.net/i348018533/article/details/51701865

https://www.cnblogs.com/lidabo/p/9077938.html

, ,
Previous Post
Compile rtorrent-0.9.4 in ubuntu 18.04

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Menu