通过nginx-build来构建nginx
我用Go语言写了一个类似于mysql-build或xbuild的nginx版本。
虽然构建nginx单独版本并不困难,但是如果想要静态地集成第三方模块、zlib、PCRE和OpenSSL等依赖库,会变得非常麻烦,因此我希望自动化处理这些问题。选择Go语言完全是出于兴趣。起初我尝试使用Shell脚本努力编写,但在原型设计阶段,由于产品的最终形态还没有确定,使用低效的工具非常困难,因此我放弃了。
安装
由于nginx-build是用Go编写的,所以首先需要安装Go。如果已经安装了Go,可以通过以下命令完成安装。
$ go get -u github.com/cubicdaiya/nginx-build
使用nginx-build构建nginx。
让我们立即使用nginx-build构建nginx。
$ uname
Darwin
$ nginx-build -v 1.9.7 -d work
nginx-build: 0.6.2
Compiler: gc go1.5.2
2015/12/08 04:55:03 Download nginx-1.9.7.....
2015/12/08 04:55:05 Extract nginx-1.9.7.tar.gz.....
2015/12/08 04:55:05 Generate configure script for nginx-1.9.7.....
2015/12/08 04:55:05 Configure nginx-1.9.7.....
2015/12/08 04:55:12 Build nginx-1.9.7.....
2015/12/08 04:55:16 Complete building nginx!
nginx version: nginx/1.9.7
built by clang 7.0.0 (clang-700.1.76)
configure arguments: --with-cc-opt=-Wno-deprecated-declarations
2015/12/08 04:55:16 Enter the following command for install nginx.
$ cd work/nginx/1.9.7/nginx-1.9.7
$ sudo make install
运用-verbose选项可以详细输出执行过程。
nginx-build -v 1.9.7 -d work -verbose
使用nginx-build来指定nginx的构建选项。
要更改nginx-build中nginx configure时附加的选项,首先要准备一个自定义的configure执行的shell脚本文件。
#!/bin/sh
./configure \
--with-http_gunzip_module \
用-C选项再次执行并指定此文件。
nginx-build -v 1.9.7 -d work -c myconfigure.sh
nginx-build: 0.6.2
Compiler: gc go1.5.2
2015/12/08 04:57:52 Download nginx-1.9.7.....
2015/12/08 04:57:54 Extract nginx-1.9.7.tar.gz.....
2015/12/08 04:57:54 Generate configure script for nginx-1.9.7.....
2015/12/08 04:57:54 Configure nginx-1.9.7.....
2015/12/08 04:58:01 Build nginx-1.9.7.....
2015/12/08 04:58:05 Complete building nginx!
nginx version: nginx/1.9.7
built by clang 7.0.0 (clang-700.1.76)
configure arguments: --with-http_gunzip_module
2015/12/08 04:58:05 Enter the following command for install nginx.
$ cd work/nginx/1.9.7/nginx-1.9.7
$ sudo make install
将来可以基于这个构建nginxenv之类的东西可能会很好。