阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

生产线上的Nginx如何添加未编译安装模块

164次阅读
没有评论

共计 3412 个字符,预计需要花费 9 分钟才能阅读完成。

正在生产线上跑着 web 前端是 nginx+tomcat, 现在有这样一个需求,需要对网站的单品页面和列表页设置缓存,不同的页面设置不同的缓存,但是由于开始没有安装 ngx_cache_purge 这个模块,现在没法直接往配置文件里边写,这时候,就需要在线安装 ngx_cache_purge 此模块,下边就说下怎么在线编译安装新模块。
安装步骤:
1. 首先看下内核和系统的版本号。
[root@vmware1 ~]# uname -a
Linux vmware1 2.6.18-308.el5 #1 SMP Tue Feb 21 20:06:06 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
[root@vmware1 ~]# lsb_release -a
LSB Version:    :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 5.8 (Final)
Release:        5.8
Codename:      Final

2. 看下编译安装 nginx 的时候,都编译安装的哪些模块。
[root@vmware1 ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.3.1
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)
TLS SNI support disabled
configure arguments: –user=nginx –group=nginx –prefix=/usr/local/nginx-1.3.1 –with-http_stub_status_module –with-http_ssl_module –with-pcre=/taokey/tools/pcre-8.33

3. 下载 proxy_cache 所需的压缩包 ngx_cache_purge-2.1.tar.gz。
[root@vmware1 tools]# wget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz
–2013-09-29 11:02:19 进到 –  http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz
Resolving labs.frickle.com… 5.9.135.91
Connecting to labs.frickle.com|5.9.135.91|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 10535 (10K) [application/octet-stream]
Saving to: `ngx_cache_purge-2.1.tar.gz’
100%[==========================================================================================>] 10,535      –.-K/s  in 0s     
2013-09-29 11:02:21 (64.8 MB/s) – `ngx_cache_purge-2.1.tar.gz’ saved [10535/10535]

4. 解压下载好的 ngx_cache_purge-2.1.tar.gz 这个压缩包
[root@vmware1 tools]# tar -xf ngx_cache_purge-2.1.tar.gz

5. 进到之前安装 nginx 这个软件包的目录
1 [root@vmware1 nginx-1.3.1]# cd /taokey/tools/nginx-1.3.1

6. 重新./configure,make 编译,不用 make install。千万要注意:到这里就可以了,千万不要 make install,不然文件就会被覆盖了。
[root@vmware1 nginx-1.3.1]# ./configure  –user=nginx  –group=nginx  –add-module=../ngx_cache_purge-2.1  –prefix=/usr/local/nginx-1.3.1  –with-http_stub_status_module  –with-http_ssl_module  –with-pcre=/taokey/tools/pcre-8.33
[root@vmware1 nginx-1.3.1]# make

7. 需要替换 nginx 二进制文件, 先备份一下原来的启动脚本。
[root@vmware1 nginx-1.3.1]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

8. 需要把 nginx 进程杀掉,不然复制会报错
[root@vmware1 nginx-1.3.1]# killall nginx
[root@vmware1 nginx-1.3.1]# killall nginx
nginx: no process killed
[root@vmware1 nginx-1.3.1]# cp ./objs/nginx /usr/local/nginx/sbin/
cp: overwrite `/usr/local/nginx/sbin/nginx’? yes

9. 此时,查看下 nginx 的所有的模块,是否把 cache_purge 这个模块成功编译进去。
[root@vmware1 nginx-1.3.1]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.3.1
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)
TLS SNI support disabled
configure arguments: –user=nginx –group=nginx –add-module=../ngx_cache_purge-2.1 –prefix=/usr/local/nginx-1.3.1 –with-http_stub_status_module –with-http_ssl_module –with-pcre=/taokey/tools/pcre-8.33

10. 开启 nginx.
[root@vmware1 nginx-1.3.1]# /usr/local/nginx/sbin/nginx
[root@vmware1 nginx-1.3.1]# netstat -anpt | grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                  LISTEN      6205/nginx

到此为止,实验结束。

推荐阅读

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx 的详细介绍 :请点这里
Nginx 的下载地址 :请点这里

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计3412字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中