在Win32平台上构建nginx
安装环境
其中:Mercurial是为了使用hg拉取nginx的源码;如果使用其他方式获取源码,则无需安装。
1、安装:Microsoft Visual Studio 2019(根据自己的需求安装相应版本)
2、安装:MSYS
3、安装:Perl
4、安装:Mercurial
5、安装:sed
6、下载:pcre
7、下载:zlib
8、下载:OpenSSL
9、下载:nginx
在cmd中输入:hg clone http://hg.nginx.org/nginx
前提条件:Mercurial安装并添加运行路径到PATH
10、下载:nginx-http-flv-module 并解压在nginx根目录的上级目录(其他目录则需要修改config中–add-module的路径为对应路径)
前置条件
Perl、Mercurial、MSYS、sed的运行路径添加到PATH
编译步骤
1、在nginx源码根目录下创建文件夹:
a) 创建objs/lib目录,并解压zlib、pcre、openssl源码到objs/lib
b) 创建logs、temp/client_body_temp、temp/fastcgi_temp、temp/proxy_temp、temp/scgi_temp、temp/uwsgi_temp
2、在Nginx源码根目录下创建config文件(无后缀),并在文件中写入:
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.44 \
--with-zlib=objs/lib/zlib-1.2.3 \
--with-openssl=objs/lib/openssl \
--with-openssl-opt=no-asm \
--with-http_ssl_module \
--add-module=../nginx-http-flv-module
3、运行MSYS bash,进入nginx的根目录
4、在nginx根目录下面的auto/cc/msvc中添加相应的MSVC的版本
5、在MSYS中运行配置脚本:./config
6、修改nginx源码根目录下的objs/Makefile中的-WX为:-WX-
7、修改zlib-1.2.3源码中的zconf.h和zconfig.in.h中的
include <unistd.h> /* for SEEK_* and off_t */
为如下:
# if defined(WINDOWS) || defined(WIN32)
# include <io.h>
# include <process.h>
# else
# include <unistd.h> /* for SEEK_* and off_t */
# endif
8、打开相应的msvc的Native Tools Command Prompt,进入到nginx源码的根目录,执行:
nmake –f objs/Makefile
发布
将nginx源码根目录下的conf、contrib、logs、temp、docs/html文件夹和objs/nginx.exe拷贝到一起即可。
测试
点击运行nginx.exe,启动成功后台运行,网页键入ip:port,即可访问;报错日志则输出到logs/error.log。