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

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

一、查看nginx版本

nginx -v
nginx: nginx version: nginx/1.2.1

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

nginx -V

--prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-pcre-jit --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/nginx-1.2.1/debian/modules/nginx-auth-pam --add-module=/build/nginx-1.2.1/debian/modules/nginx-echo --add-module=/build/nginx-1.2.1/debian/modules/nginx-upstream-fair --add-module=/build/nginx-1.2.1/debian/modules/nginx-dav-ext-module

其实后面几个add_module 参数如果不需要,可以去掉的

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

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

把刚才的configure参数放进来并增加新的fancyindex

./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-pcre-jit --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=./ngx-fancyindex-master

四、编译nginx

make

注意不要make install,make install会覆盖安装

在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-xpm libgd2-xpm-dev

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

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

备份旧的nginx程序

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

把新的nginx程序覆盖旧的

cp objs/nginx /usr/sbin/nginx

测试新的nginx程序是否正确

/usr/sbin/nginx -t

nginx: theconfiguration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx:configuration file /usr/local/nginx/conf/nginx.conf test issuccessful

平滑重启nginx

/usr/local/nginx/sbin/nginx -s reload

发表评论

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