您的位置:首页 > 运维架构 > Nginx

Windows下从源码编译Nginx(学习笔记)

2015-02-22 23:51 567 查看
在制作xServer集成环境Windows版过程中,发现官方编译版组件较少,故自行从源码编译了Nginx,下面为详细步骤。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

一、下载如下文件

VS2008 http://download.microsoft.com/download/3/0/2/3025EAE6-2E15-4972-972A-F5B1ED248E85/VS2008ExpressWithSP1CHSX1504735.iso
Perl http://strawberry-perl.googlecode.com/files/strawberry-perl-5.16.3.1-32bit.msi
Mercurial http://mercurial.selenic.com/downloads/
MinGW http://sourceforge.net/projects/mingw/files/latest/download
OpenSSL http://www.openssl.org/source/openssl-1.0.1e.tar.gz
Pcre http://nchc.dl.sourceforge.net/project/pcre/pcre/8.32/pcre-8.32.zip
Zlib http://zlib.net/zlib-1.2.8.tar.gz
subs_filter https://codeload.github.com/yaoweibin/ngx_http_substitutions_filter_module/zip/master
二、编译nginx

1、安装VS2008、Perl、Mercurial,分别对应C++编译环境、Perl脚本运行时、Hg源码仓库客户端

2、安装MinGW管理器,添加MSYS模块,其他模块可以不安装,用于生成Makefile文件

a、使用C:\ProgramFiles\MicrosoftVisualStudio9.0\VC\bin\link.exe替换C:\MinGW\msys\1.0\bin\link.exe

b、编辑C:\MinGW\msys\1.0\msys.bat在@echooff下面加入:call"C:\Program
Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"

3、将OpenSSL、Pcre、Zlib分别解压到目录c:\nginx\objs\lib\{openssl-1.0.1e,pcre-8.32,zlib-1.2.8}中

4、检出nginx源码,命令:hgclone--verbose--http://hg.nginx.org/nginx
c:\nginx

a.编辑c:\nginx\src\core\nginx.h修改服务器名称

b.替换c:\nginx\src\os\win32\nginx.ico自定义软件图标

c.将subs_filter解压到c:\nginx\objs\module\http_subs_filter

编辑文件ngx_http_subs_filter_module.c,将ngx_regex_compile_t rc;移动到当前函数顶部,否则编译出错

5、把下面命令写入到c:\nginx\mkngx,然后在msys中执行该文件

auto/configure--with-cc=cl--builddir=objs--prefix=--sbin-path=nginx.exe--conf-path=conf/nginx.conf\

--pid-path=logs/nginx.pid--http-log-path=logs/access.log--error-log-path=logs/error.log\

--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-select_module--with-ipv6--with-mail\

--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_random_index_module--with-http_secure_link_module\

--with-pcre=objs/lib/pcre-8.32--with-zlib=objs/lib/zlib-1.2.8--with-openssl=objs/lib/openssl-1.0.1e\

--with-openssl-opt=enable-tlsext--with-http_ssl_module--with-mail_ssl_module\

--add-module=objs/module/http_subs_filter

mkdirobjs/{conf,logs}

nmake-fobjs/Makefile

6、执行上述步骤时可能会提示找不到stdin.h文件

编辑c:\nginx\objs\lib\pcre-8.32\config.h,删除如下内容

#ifndef
HAVE_INTTYPES_H

#define
HAVE_INTTYPES_H 1

#endif

#ifndef
HAVE_STDINT_H

#define
HAVE_STDINT_H 1

#endif

原文地址:http://www.anrip.com/post/1321
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: