第一步:在宝塔安装nginx,选择编译安装
第二步:在这个基础上加新增模块nginx_upstream_check_module,步骤如下
1.执行命令获取nginx_upstream_check_module模块:
wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master
2.进入nginx安装的目录
[root@hlt ~]# ps -ef|grep nginx
root 16986 1 0 16:59 ? 00:00:00 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
www 16987 16986 0 16:59 ? 00:00:00 nginx: worker process
www 16988 16986 0 16:59 ? 00:00:00 nginx: worker process
www 16989 16986 0 16:59 ? 00:00:00 nginx: worker process
www 16990 16986 0 16:59 ? 00:00:00 nginx: worker process
www 16991 16986 0 16:59 ? 00:00:00 nginx: worker process
www 16992 16986 0 16:59 ? 00:00:00 nginx: worker process
www 16993 16986 0 16:59 ? 00:00:00 nginx: worker process
www 16994 16986 0 16:59 ? 00:00:00 nginx: worker process
www 16995 16986 0 16:59 ? 00:00:00 nginx: cache manager process
root 17091 17077 0 17:18 pts/1 00:00:00 grep nginx
[root@hlt ~]# cd /www/server/nginx/src/
3.打补丁找到nginx-1.14.2对应支持的nginx_upstream_check_module(不同版本请各自对应)
patch -p1 < /home/hwfwqlzh/nginxTool/nginx_upstream_check_module-master/check_1.14.0+.patch
4.运行 -V命令获取当前的编译配置,命令 /www/server/nginx/sbin/nginx -V
拷贝显示出来的内容 configure arguments:之后的内容我的是 --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx****** 后面很长的,自己复制自己服务器上的内容
5.在/www/server/nginx/src/目录下运行下面的代码./configure 后面的内容是刚刚上面获取的,在里面加入了紫色的代码紫色的代码路径是解压的第一步下载的文件:
./configure --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/home/hwfwqlzh/nginxTool/nginx_upstream_check_module-master --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc
6.运行 make 命令 运行后的编译文件在 /www/server/nginx/src/objs/nginx
7.备份 cp /www/server/nginx/sbin/nginx /www/server/nginx/sbin/nginx.bak
8.cp /www/server/nginx/src/objs/nginx /www/server/nginx/sbin/
9.配置文件加入check模块
#===============check 测试==========================
upstream mycheck {
server 127.0.0.1:8080;
server 127.0.0.1:8083;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "GET /zzbNew/url.jsp HTTP/1.0\r\n\r\n";
}
server {
listen 80;
server_name booking.homilychart.com;
location / {
proxy_pass http://mycheck;
}
location /status {
check_status;
access_log off;
# allow 172.29.73.23;
# deny all;
}
}
#===============check 测试==========================
url.jsp 内容如下:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String por = request.getLocalAddr()+":"+request.getLocalPort();
request.setAttribute("por", por);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'url.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style>
body{text-align:center}
</style>
</head>
<body>
<br>
<h1>Server IP: ******</h1>
<h1>Test Server ${por}</h1>
</body>
</html>
10.运行重启nginx测试