Windows和Linux下编译nginx

一、Windows下编译nginx

(一)准备

首先得下载安装msys2(具体可以参考博文《windows下使用msys2编译FFmepg源码》)。

下载nginx源码,链接:http://hg.nginx.org/

下载nginx-http-flv-module,链接:GitHub - winshining/nginx-http-flv-module: A media streaming server based on nginx-rtmp-module. In addtion to the features nginx-rtmp-module provides, HTTP-FLV, GOP cache, VHost (one IP for multi domain names) and JSON style statistics are supported now.

下载pcre,链接:https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz。注意,这里如果下载最新版本的pcre可能编译会报错。所以下载8.43版本的。

下载zlib,链接:zlib Home Site

下载openssl,链接:/source/index.html

(二)编译nginx

在msys安装目录下新建文件夹SourceCode,将下载下来的nginx源码拷贝并解压到该目录中。

在nginx源码目录中新建目录objs\lib,将nginx-http-flv-module、openssl、pcre、zlib拷贝到该目录中并解压。

在nginx-f2ff291bbdac目录中创建目录logs、temp\client_body_temp、temp\proxy_temp、temp\fastcgi_temp、temp\scgi_temp。

运行msys2_shell.cmd,进入nginx-f2ff291bbdac目录,执行命令:

auto/configure --with-cc=cl --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.43 --with-zlib=objs/lib/zlib-1.2.11 --with-openssl=objs/lib/openssl-3.0.0-alpha15 --with-openssl-opt=no-asm --with-select_module --with-http_ssl_module --with-http_sub_module --with-http_v2_module --add-module=objs/lib/nginx-http-flv-module-master

如果提示:auto/cc/msvc: line 117: [: : integer expression expected。在auto/cc/msvc文件中,在下面的这个位置中添加NGX_MSVC_VER=19.11,再重新configure。

以管理员身份运行vs2015开发人员命令提示,执行命令:

nmake -f objs/Makefile

编译可能会出现error:警告被视为错误 - 没有生成“object”文件。

打开nginx源码目录的objs目录下的Makefile

将第三行CFLAGS =  -O2  -W4 -WX -nologo -MT -Zi -Fdobjs/nginx.pdb -DFD_SETSIZE=1024 -DNO_SYS_TYPES_H

改为:CFLAGS =  -O2  -W3 -nologo -MT -Zi -Fdobjs/nginx.pdb -DFD_SETSIZE=1024 -DNO_SYS_TYPES_H

重新编译,然后最后可能会出现提示信息:'sed' 不是内部或外部命令,也不是可运行的程序。不用管这个提示。在nginx-f2ff291bbdac\objs目录下生成了nginx.exe,表示编译成功了。

二、Linux下编译nginx

(一)准备

下载nginx源码,链接:nginx: download

下载nginx-http-flv-module,链接:

Releases · winshining/nginx-http-flv-module · GitHub

将nginx-XXX.tar.gz和nginx-http-flv-module-XXX.tar.gz分别解压缩,进入nginx源码目录

执行命令:

./configure --add-module=/root/NfsShareDir/trunk/avs/third_party/nginx/nginx-http-flv-module-1.2.11

其中,“/root/NfsShareDir/trunk/avs/third_party/nginx/nginx-http-flv-module-1.2.11”是nginx-http-flv-module的源码目录。

然后

make
ls objs/

可以看到在objs目录下生成了nginx的可执行文件

三、参考文章

Nginx Windows下编译和安装

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值