您的位置:首页 > 运维架构 > Nginx

nginx添加模块

2016-11-03 16:46 155 查看
ubuntu彻底删除nginx

sudo apt-get --purge remove nginx 删除nginx,–purge包括配置文件

sudo apt-get autoremove 自动移除全部不使用的软件包

dpkg --get-selections|grep nginx 罗列出与nginx相关的软件

sudo apt-get --purge remove nginx

sudo apt-get --purge remove nginx-commonsudo apt-get --purge remove nginx-core

ps -ef |grep nginx 查看nginx正在运行的进程,如果有就kill掉

sudo find / -name nginx* 全局查找与nginx相关的文件

sudo rm -rf file

然后重装

sudo apt-get updatesudo apt-get install nginx

nginx平滑添加模块(包括apt安装)

1.先查看nginx版本

nginx -V

nginx version: nginx/1.4.6

built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1)

TLS SNI support enabled

configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --add-module=/home/xiexie/nginx-http-concat --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

2.官网下载相同版本的nginx

3.添加模块

下载要添加的模块,如果是第三方则需要下载,然后指定添加路径(就是下载第三方的路径),以淘宝ngx_http_concat_module模块为列 --add-module=/home/xiexie/nginx-http-concat ,如果是自带的模块比如 ssl --with-http_ssl_module

编译时加上之前查看版本的信息比如

./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --add-module=/home/xiexie/nginx-http-concat --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

编译过程可能报错,需要安装以下几个软件

sudo apt-get install libxml2 libxml2-dev libxslt-dev

sudo apt-get install libgd2-xpm libgd2-xpm-dev

sudo apt-get install geoip-database libgeoip-dev

apt-get install libpcre3 libpcre3-dev

编译成功后make,记住千万不要make install ,这样会覆盖你以前的nginx

这时候nginx -V 查看应该还没有添加的模块信息,这时先killall nginx

whereis nginx 查看一下,找到/usr/sbin/nginx 或者/usr/loacal/sbin/nginx ,为了以防万一,备份nginx mv /usr/sbin/nginx /usr/sbin/nginx.bak

然后复制编译目录下 cp ./objs/nginx /usr/local/nginx/sbin/

这时候再查看应该就加载成功了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: