新版本nginx-0.7.50编译安装过程
[2009-08-24 21:33:29]
新版本的nginx-0.7.50默认加入了proxy cache,所以按之前的编译参数安装不上,就算是加上--without-http-cache,也不能编译通过。因为nginx-0.7是测试分支,所以作者可以随心所欲,你却不能由此而破口大骂他。
要解决此问题,办法也是有的:
1、暴力地装上proxy cache
要装上proxy cache,必定得有openssl的开发(dev)版,proxy cache会利用到里面的一些声明。几乎所有的linux都有openssl,但未必有openssl-dev。在debian里,用apt-get装这些玩意十分方便,可惜的是我的机器并不全部是debian的,为了统一操作,下一个来装。
wget http://www.openssl.org/source/openssl-0.9.8k.tar.gz
tar -zxvf openssl-0.9.8k.tar.gz
cd openssl-0.9.8k
./config
make
make install
这样安装后openssl会被安装到/usr/local/ssl/目录下,编译这个玩意花时间比较久,等吧。然后开始编译nginx,因为都已经弄了openssl,不如把nginx的ssl模块也顺便装了去。
./configure --with-http_realip_module --prefix=/usr/local/nginx --with-md5=/usr/lib --with-sha1=/usr/lib --with-http_sub_module --with-cc-opt="-I /usr/include/pcre -I /usr/local/ssl/include" --with-http_ssl_module --with-openssl=/usr/local/ssl/lib/
make -j10
make install
这样就能装完了。
2、修改代码去掉proxy cache
首先,我们用常规的编译参数去尝试编译一下:
./configure --with-http_realip_module --prefix=/usr/local/nginx --with-md5=/usr/lib --with-sha1=/usr/lib --with-openssl=/usr/lib --with-http_sub_module --with-cc-opt="-I /usr/include/pcre" --without-http-cache
make
可以看到nginx编译过程中出错了,编译失败,屏幕上有一些提示:
src/http/ngx_http_upstream.c: In function 'ngx_http_upstream_process_cache_control':
src/http/ngx_http_upstream.c:2839: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c:2843: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c:2883: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c: In function 'ngx_http_upstream_process_expires':
src/http/ngx_http_upstream.c:2896: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c:2900: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c:2911: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c: In function 'ngx_http_upstream_process_accel_expires':
src/http/ngx_http_upstream.c:2927: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c:2944: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c:2955: error: 'ngx_http_request_t' has no member named 'cache'
make[1]: *** [objs/src/http/ngx_http_upstream.o] Error 1
make[1]: Leaving directory `/home/download/nginx-0.7.50'
make: *** [build] Error 2
好,不就是有几个错么,改之:
vi src/http/ngx_http_upstream.c
敲2839,就是错误里提示的有问题的行,然后按shift+G转到那行:
if (r->cache == NULL) {
return NGX_OK;
}
if (r->cache->valid_sec != 0) {
return NGX_OK;
}
就是r->cache这里出错了,所以这些行可以注释掉,如何注释?在vi编辑器按一下gg回到文件的顶部,可见:
#if (NGX_HTTP_CACHE)
static ngx_int_t ngx_http_upstream_cache(ngx_http_request_t *r,
ngx_http_upstream_t *u);
static ngx_int_t ngx_http_upstream_cache_send(ngx_http_request_t *r,
ngx_http_upstream_t *u);
#endif
用这个#if和#endif标签注释就好啦:
#if (NGX_HTTP_CACHE)
if (r->cache == NULL) {
return NGX_OK;
}
if (r->cache->valid_sec != 0) {
return NGX_OK;
}
#endif
好,按ctrl+x退出,再make一次(不必要重新./configure)。
src/http/ngx_http_upstream.c: In function 'ngx_http_upstream_process_cache_control':
src/http/ngx_http_upstream.c:2885: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c: In function 'ngx_http_upstream_process_expires':
src/http/ngx_http_upstream.c:2898: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c:2902: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c:2913: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c: In function 'ngx_http_upstream_process_accel_expires':
src/http/ngx_http_upstream.c:2929: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c:2946: error: 'ngx_http_request_t' has no member named 'cache'
src/http/ngx_http_upstream.c:2957: error: 'ngx_http_request_t' has no member named 'cache'
make[1]: *** [objs/src/http/ngx_http_upstream.o] Error 1
make[1]: Leaving directory `/home/download/nginx-0.7.50'
make: *** [build] Error 2
比较一下上一次的错误,可以看到错误少了两行,好,按这个办法,把剩下的有错的行都注释吧,错误就是这么几行,还好。
改完之后再make之,发现能顺利编译完成,make install就可完成编译。
这个办法修改了nginx代码,但是能显著减少编译安装的时间,因为编译openssl实在是太费时了。