Contents

How to Add Health Check Module for Nginx

Install dependencies (openssl, pcre, zlib)

apt install openssl libssl-dev
apt install libpcre3 libpcre3-dev
apt install zlib1g-dev

Download nginx

cd ~
wget 'http://nginx.org/download/nginx-1.16.1.tar.gz'
tar -xzvf nginx-1.16.1.tar.gz

Download health check module

git clone git@github.com:yaoweibin/nginx_upstream_check_module.git

Build

cd nginx-1.16.1/
patch -p1 < ../nginx_upstream_check_module/check_1.16.1+.patch

./configure --add-module=../nginx_upstream_check_module --prefix=/etc/local/nginx --with-http_ssl_module

make && make install

Add nginx config

upstream backend {
    server 172.18.34.72:8801;
    server 172.18.110.51:8801;
    check interval=3000 rise=2 fall=5 timeout=1000 type=http;
    check_http_send "GET /api/nginx HTTP/1.0\r\n\r\n";   # 路由
    check_http_expect_alive http_2xx;    # staus code 形如2xx视为成功
}

Start nginx

cd /etc/local/nginx
./sbin/nginx

Other

Install gcc

apt install build-essential
apt install manpages-dev
gcc --version