windows平台下编译nginx相关问题处理

WBOY
Freigeben: 2016-08-08 09:26:57
Original
1600 Leute haben es durchsucht
本文讲述如何在windows下编译nginx,参考这篇文章 Building nginx on the Win32 platform with Visual C ,它已经讲得比较详细了,但是实际操作过程中总有很多细节问题,在这里记录下来。

Contents [hide]

  • 1 常见问题
    • 1.1 获取指定版本
    • 1.2 “stdint.h”: No such file or directory
    • 1.3 “openssl/ssl.h”: No such file or directory
    • 1.4 无法打开文件 “objs/lib/openssl-1.0.1e/lib/ssleay32.lib”
    • 1.5 error C2220: 警告被视为错误 – 没有生成“object”文件
    • 1.6 fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include “ngx_config.h””?
    • 1.7 每次编译的时候都完全编译
  • 2 操作流程总结

常见问题

我使用的VS版本是VS2008,遇到了以下问题。

获取指定版本

有时候我们需要的不是最新版本,比如我要下载1.20版本的nignx,首先,我 这里 找1.20的版本号码,很快我找到是f582d662cc408eb7a132c21f4b298b71d0701abb,以下执行顺序就可以拿到指定版本:

hg clone http://hg.nginx.org/nginx cd nginx hg co f582d662cc408eb7a132c21f4b298b71d0701abb

“stdint.h”: No such file or directory

这个问题好办,下载缺少的头文件就行了。 https://code.google.com/p/msinttypes/
解压后将头文件目录 C:\Program Files\Microsoft Visual Studio 9.0\VC\include 下面(或者类似的目录)。

“openssl/ssl.h”: No such file or directory

执行 nmake -f objs/Makefile 的时候,可能会出现这样的问题。我们看到这样的路径(objs/lib/openssl-1.0.1e/openssl/include),其实是没有的。办法就是将openssl-1.0.1e/openssl改成openssl-1.0.1e。

vi nginx/objs/Makefile

或者直接修改生成Makefile的配置

vi auto/lib/openssl/conf vi auto/lib/openssl/make

无法打开文件 “objs/lib/openssl-1.0.1e/lib/ssleay32.lib”

不知道nginx项目为什么不生成openssl的库,我通过单独编译生成openssl来解决这个问题。步骤如下:

  • 安装perl(我用ActivePerl)
  • 解压openssl到C盘,cd C:\openssl-1.0.1e
  • 执行perl Configure VC-WIN32
  • 运行cmd,将 *”C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.BAT”* 拉到cmd里运行
  • cmd内执行 ms\do_ms
  • cmd内执行 nmake -f ms\ntdll.mak

好了,将手工生成的 libeay32.lib 和 ssleay32.lib 放到目录 nginx/objs/lib/openssl-1.0.1e 下。问题解决。

error C2220: 警告被视为错误 – 没有生成“object”文件

将 CFLAGS 的 -WX 字段去掉,然后重新生成Makefile以及重新编译

vi auto/cc/msvc #CFLAGS="$CFLAGS -WX"

fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include “ngx_config.h””?

windows模块开发中会遇到的问题,每个源文件第一行代码必须添加 #include “ngx_config.h”* ,如果不想这样做就吧编译参数 *-Yungx_config.h 去掉。

每次编译的时候都完全编译

执行这行代码的时候 nmake -f objs/Makefile ,每次都要完全编译,好浪费时间啊。原因是这样的,文件 objs/Makefile 里有这样一行:

objs/lib/openssl-1.0.1e/include/openssl/ssl.h: objs/Makefile

ssh.h 文件依赖于 objs/Makefile*,但是如果前者修改时间永远都比后者早,就永远都要执行后面的命令了。把字符串 *objs/Makefile 去掉就行了。

操作流程总结

  • “C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat”
  • “C:\MinGW\msys\1.0\msys.bat”
  • cd /c/nginx
  • 生成makefile
auto/configure --with-cc=cl --builddir=objs --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 \ --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=objs/lib/pcre-8.32 \ --with-zlib=objs/lib/zlib-1.2.7 --with-openssl=objs/lib/openssl-1.0.1e \ --with-select_module --with-http_ssl_module --with-ipv6 \ --add-module=objs/lib/naxsi-core-0.48/naxsi_src
  • nmake -f objs/Makefile
  • 启动nginx
start nginx.exe -p "C:\nginx" nginx.exe -p "C:\nginx" -s reload nginx.exe -p "C:\nginx" -s quit

参考资料:
Windows下OpenSSL安装配置

本文由吴遥编写,转载请注明出处。
文章链接:http://www.wuyao721.com/nginx-building-windows.html

以上就介绍了windows平台下编译nginx相关问题处理,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!