0

重新编译Nginx添加模块

Posted by 撒得一地 on 2016年3月18日 in nginx笔记

nginx安装成功后,发现有一些其他模块没有编译进去,或者想额外添加一些模块,这时候就要重新编译nginx。

首先,查看之前编译的一些参数,比如:

[root@lmode nginx]# /usr/local/nginx/nginx -V
nginx version: nginx/1.4.7
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) 
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-pcre=/usr/local/src/lnmp/pcre-8.33 --with-zlib=/usr/local/src/lnmp/zlib-1.2.8 --with-openssl=/usr/local/src/lnmp/openssl-1.0.1e 

比如我现在要新增–with-http_ssl_module 、–with-http_gzip_static_module 这些模块参数,那么我只要把这些参数添加进去然后重新编译即可,需要注意的是原先编译过的参数也要加进来。过程如下:

进入nginx源码包

[root@lmode nginx]# cd /usr/local/src/nginx-1.4.7

将要编译的参数重新添加到后面

[root@lmode nginx-1.4.7]# ./configure --prefix=/usr/local/nginx --user=www --group=www --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid  --with-pcre=/usr/local/src/lnmp/pcre-8.33 --with-zlib=/usr/local/src/lnmp/zlib-1.2.8 --with-openssl=/usr/local/src/lnmp/openssl-1.0.1e --with-http_gzip_static_module --with-http_ssl_module

注意:这里只能make 千万别make install,否则就覆盖安装了

[root@lmode nginx-1.4.7]# make

make完成后,在源码目录下会有一个objs目录,objs目录下就多了个nginx,这个就是新版本的程序了。

[root@lmode nginx-1.4.7]# ls

auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

然后将objs目录下的nginx替换之前已经安装过的nginx。

先备份旧的nginx程序

[root@lmode nginx-1.4.7]#cp /usr/local/nginx/nginx  /usr/local/nginx/nginx.bak

把新的nginx程序覆盖旧的

[root@lmode nginx-1.4.7]#cp ./objs/nginx /usr/local/nginx/sbin/nginx

如果提示“cp:cannot create regular file `/usr/local/nginx/sbin/nginx': Text file busy”

建议使用如下语句cp

	#cp -rfp objs/nginx /usr/local/nginx/sbin/nginx

测试新的nginx程序是否正确

[root@lmode nginx-1.4.7]# /usr/local/nginx/nginx -t
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful

最后重启nginx

[root@lmode nginx-1.4.7]# /usr/local/nginx/nginx -s reload

这样,就安装成功了。下面介绍下安装第三方模块的方法。

安装第三方模块

nginx安装第三方模块的方法和上面差不多,只是要额外添加一个–add-module参数:

./configure --prefix=/你的安装目录  --add-module=/第三方模块目录

下面以安装pagespeed模块位实例

# ./configure --prefix=--prefix=/usr/local/nginx --user=www --group=www --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid  --with-pcre=/usr/local/src/lnmp/pcre-8.33 --with-zlib=/usr/local/src/lnmp/zlib-1.2.8 --with-openssl=/usr/local/src/lnmp/openssl-1.0.1e --with-http_gzip_static_module --with-http_ssl_module --add-module=../ngx_pagespeed-master

# make

# cp ./objs/nginx /usr/local/nginx/nginx

# /usr/local/nginx/nginx -s reload

总结

安装nginx安装第三方模块实际上是使用–add-module重新安装一次nginx,不要make install而是直接把编译目录下objs/nginx文件直接覆盖老的nginx文件.如果你需要安装多个nginx第三方模块,你只需要多指定几个相应的–add-module即可。

[warning]备注:重新编译的时候,记得一定要把以前编译过的模块一同加到configure参数里。

本文固定地址:http://coderschool.cn/1728.html,转载请注明。

上一篇:

下一篇:

相关推荐

发表评论

电子邮件地址不会被公开。 必填项已用*标注

9 + 5 = ?

网站地图|XML地图

Copyright © 2015-2024 技术拉近你我! All rights reserved.
闽ICP备15015576号-1 版权所有©psz.