apt-get方式安装nginx后,重新编译增加substitutions模块

为保险起见下载和apt-get安装的一样的版本

一、查看nginx版本

nginx -v
nginx: nginx version: nginx/1.4.6

二、查看apt-get安装的编译参数

root@ubuntu:~# nginx -V
nginx version: nginx/1.4.6 (Ubuntu)
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module

三、下载相同版本的源码包

wget http://www.nginx.org/download/nginx-1.4.6.tar.gz
tar zxf nginx-1.4.6.tar.gz
cd nginx-1.4.6

下载ngx_http_substitutions

https://github.com/yaoweibin/ngx_http_substitutions_filter_module/archive/master.zip

github手动下载地址:https://github.com/yaoweibin/ngx_http_substitutions_filter_module/

把刚才的configure参数放进来并增加新的ngx_http_substitutions_filter_module-master

./configure --with-cc-opt='''-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2''' --with-ld-opt='''-Wl,-Bsymbolic-functions -Wl,-z,relro''' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=./ngx_http_substitutions_filter_module-master

四、编译nginx

make

注意:

1、一般来说,默认./configure 生成的makefile文件都将带上-g选项,这对于利用gdb调试nginx是非常必要的,但会debug模式会插入很多跟踪和ASSERT之类,造成编译的nginx文件很大。make之前编辑去掉objs/Makefile文件中下面这一行的 -g -g参数可以显著的缩写编译生成的nginx程序的体积。

CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g

2、不要make install,make install会覆盖安装

3、在configure时可能会报一些错误,简列如下

1. rewrite需要pcre支持
./configure: error: the HTTP rewrite module requires the PCRE library.
apt-get install libpcre3 libpcre3-dev

2. http cache需要openssl
./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.
apt-get install libssl-dev openssl

3. 安装libxslt
./configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries.
apt-get install libxslt-dev

4. 缺少GD library
./configure: error: the HTTP image filter module requires the GD library.
apt-get install libgd2-noxpm-dev libgd2-xpm-dev

5. 安装GeoIP library
./configure: error: the GeoIP module requires the GeoIP library.
apt-get install libgeoip-dev

6.需要安装make

apt-get install make

五、替换nginx程序

make完之后在objs目录下就多了个nginx,这个就是新版本的程序了

备份旧的nginx程序

cp /usr/sbin/nginx /usr/sbin/nginx.bak

把新的nginx程序覆盖旧的

service nginx stop

cp objs/nginx /usr/sbin/nginx

测试新的nginx程序是否正确

/usr/sbin/nginx -t

nginx: theconfiguration file /etc/nginx/nginx.conf syntax is ok

nginx:configuration file /etc/nginx/nginx.conf test issuccessful

平滑重启nginx

/usr/sbin/nginx -s reload

发表回复

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