1 查看版本和参数
/usr/local/webserver/nginx/sbin/nginx -V
configure arguments: --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
2 下载对应版本的tar.gz包到/usr/local/src/解压
http://nginx.org/download/nginx-1.16.1.tar.gz
3 添加模块,通过--with-http_v2_module启用ngx_http_v2_module模块
cd /usr/local/src/nginx-1.16.1
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35 --with-http_v2_module
4 make,注意不要make install,否则直接覆盖了
5 备份,覆盖新的nginx。
#meke好了之后会在源码目录下objs 目录下产生nginx的二进制,然后把原先的nginx二进制命令备份,用上面编译好的nginx替换,最后reload的nignx就可以
cp /usr/local/webserver/nginx/sbin/nginx{ ,.bak}
cp -fr /usr/local/src/nginx-1.16.1/objs/nginx /usr/local/webserver/nginx/sbin/nginx
/usr/local/webserver/nginx/sbin/nginx -s reload
6 重新查看/usr/local/webserver/nginx/sbin/nginx -V
configure arguments: --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-pcre=/usr/local/src/pcre-8.35
添加nginx_upstream_check_module 模块实现健康状态检测
参考 https://github.com/yaoweibin/nginx_upstream_check_module
# 操作目录 /opt/nginx
cd /opt/nginx
# 安装git
yum install -y git
# 拉取源码
git clone https://github.com/yaoweibin/nginx_upstream_check_module.git
# 安装打补丁软件
yum -y install patch
# nginx解压目录 /opt/nginx/nginx-1.18.0
cd /opt/nginx/nginx-1.18.0
# 给nginx打补丁(根据nginx版本号选择补丁包),打补丁这步操作不可少,否则会出出"[error] 29841#0: *23 http upstream check module can not find any check server, make sure you've added the check servers," 错误
patch -p1 < /opt/nginx/nginx_upstream_check_module/check_1.16.1+.patch
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-stream --add-module=/opt/nginx/nginx_upstream_check_module
# 编译
make
# 进入objs,编译好的nginx在这个目录里
cd /opt/nginx/nginx-1.18.0/objs
# 备份旧的nginx
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
# 替换nginx
cp nginx /usr/local/nginx/sbin/nginx
systemctl restart nginx