新安装和已安装nginx如何添加未编译安装模块/补丁
--http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=10485&page=1&extra=#pid105098
新安装nginx如何添加未编译安装模块/补丁
之前发过一篇nginx如何添加未编译安装模块/补丁,那篇是安装nginx之后的,nginx已经在跑了,这一篇新安装nginx
http://www.apelearn.com/bbs/thread-10429-1-1.html
比如要安装 ngx_req_status模块 统计流量的
yum -y install patch unzip gcc pcre pcre-devel zlib zlib-devel openssl-devel openssl -y
mkdir /download;cd /download
wget http://nginx.org/download/nginx-1.4.6.tar.gz &&
wget https://github.com/zls0424/ngx_req_status/archive/master.zip -O ngx_req_status.zip
unzip /download/ngx_req_status.zip -d /usr/local/
tar -zxvf nginx-1.4.6.tar.gz
cd nginx-1.4.6
patch -p1 < /usr/local/ngx_req_status-master/write_filter.patch # patch命令进行打补丁
./configure --prefix=/usr/local/nginx --with-pcre
--with-http_gzip_static_module --with-http_ssl_module
--add-module=/usr/local/ngx_req_status-master && make -j2 && make install #启用2个cpu去编译,2个job,提高编译速度
rm -rf /usr/local/ngx_req_status-master
#启动nginx
/usr/local/nginx/sbin/nginx
#修改nginx.conf
http {
req_status_zone server_name $server_name 256k;
req_status_zone server_addr $server_addr 256k;
req_status_zone server_url $server_name$uri 256k;
req_status server_name server_addr server_url;
server {
listen 8080;
server_name test.com;
location /ttlsa-req-status {
allow 192.168.1.6;
allow 192.168.2.8;
deny all;
req_status_show on;
}
}
}
#reload一下/usr/local/nginx/sbin/nginx -s reload
#修改Windows的hosts文件
http://test.com:8080/ttlsa-req-status
#http://www.ttlsa.com/nginx/nginx-custom-header-to-return-information-module-ngx_headers_more/ 隐藏服务器的软件版本改为tomcat 7
sed -i 's/Server: nginx/Server: tomcat/' /download/nginx-1.4.6/src/http/ngx_http_header_filter_module.c
sed -i 's/1.4.6/7.0.52/' /download/nginx-1.4.6/src/core/nginx.h
sed -i 's/nginx//tomcat/' /download/nginx-1.4.6/src/core/nginx.h
cat > /etc/ld.so.conf << EOF
> include ld.so.conf.d/*.conf
> /usr/local/lib #动态装入器将在/usr/local/lib 中查找共享库。
> EOF
ldconfig 更新ld.so.cache 文件,以读取最新的/etc/ld.so.conf
nginx如何添加未编译安装模块/补丁 [复制链接]
--http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=10429&page=1&extra=#pid103693
有这样一个增强的负载均衡模块,我们知道php添加扩展模块很容易,但是nginx呢?
下面是教程
“公平的”Nginx 负载均衡模块,增强了Nginx 提供的round-robin 负载均衡算法,可以跟踪后端服务器的负载来分发请求。
配置范例:
upstream mongrel {
fair;
server 127.0.0.1:5000;
server 127.0.0.1:5001;
server 127.0.0.1:5002;
}
原已经安装好的nginx,现在需要添加一个未被编译安装的模块:
nginx -V 可以查看原来编译时都带了哪些参数
--prefix=/usr/local/nginx --with-pcre --with-http_gzip_static_module --with-http_ssl_module --user=nginx --group=nginx --add-module=/usr/local/ngx_req_status-master
wget -O nginx-upstream-fair.zip https://github.com/gnosek/nginx-upstream-fair/archive/master.zip
步骤如下:
unzip /download/nginx-upstream-fair.zip -d /usr/local/
tar -zxvf nginx-1.4.6.tar.gz
cd nginx-1.4.6 #上面nginx -V 查出来的编译参数这里原样加上
./configure --prefix=/usr/local/nginx --with-pcre --with-http_gzip_static_module --with-http_ssl_module --user=nginx --group=nginx --add-module=/usr/local/ngx_req_status-master/ --add-module=/usr/local/nginx-upstream-fair-master/
#不要make install,否则就是覆盖安装,生成的nginx二进制文件放在当前目录的objs/下
make
替换nginx二进制文件:
cp /usr/local/nginx/sbin/nginx{,.bak}
/etc/init.d/nginx stop
cp /download/nginx-1.4.6/objs/nginx /usr/local/nginx/sbin/
rm -rf /usr/local/{nginx-upstream-fair-master,ngx_req_status-master}
f