nginx windows 本地编译版本 - 支持健康检查

背景说明

nginx 官网提供 windows 版本,但官方版本没有编译 nginx_upstream_check_module 模块,导致康健检查不能用

解决方案

下载别人编译好的版本,或者本地编译,前者网上没有找到合适的版本,于是乎,就自己编译一个呗。
官方文档:
https://nginx.org/en/docs/howto_build_on_win32.html

工具集

Visual Studio + MSYS + ActivePerl

依赖组件

pcre-8.45 + zlib-1.3 + openssl-3.0.12

编译过程

auto/configure --with-cc=cl --with-debug --prefix= --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --http-scgi-temp-path=temp/scgi_temp --http-uwsgi-temp-path=temp/uwsgi_temp --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=objs/lib/pcre-8.45 --with-zlib=objs/lib/zlib-1.3 --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_slice_module --with-mail --with-stream --with-openssl=objs/lib/openssl-3.0.12 --with-openssl-opt='no-asm no-tests -D_WIN32_WINNT=0x0501' --with-http_ssl_module --with-mail_ssl_module --with-stream_ssl_module --add-module=../nginx_upstream_check_module-master/

nmake

编译问题处理

如下两个帖子有详细说明,可以参考解决
https://blog.csdn.net/qq_24054301/article/details/112131057
https://blog.csdn.net/qq_24054301/article/details/112156013

测试运行

因为编译选项已官方版本基本一致,所以直接把编译好的 nginx.exe 替换官方版本的文件即可。
nginx.conf 需要配置健康检查的两个内容,一是 upstream,二是 location

upstream mes {
 #ip_hash; 
 server 10.35.1.71:8080;
 server 10.35.1.72:8080;

 check interval=3000 rise=2 fall=5 timeout=1000 type=http;
# 配置一个连接发送的请求数
 check_keepalive_requests 100;
# 发送HEAD请求,请求头必须包含Host,否则返回400 Bad Request
 check_http_send "HEAD /prj-xhzj-web/ HTTP/1.1\r\nHost: localhost:8080\r\nConnection: keep-alive\r\n\r\n";
# 默认认为2XX和3XX的状态是健康的
 check_http_expect_alive http_2xx http_3xx;
 }
        location  /status {
            check_status;
            access_log off;
            charset utf-8;
        }

运行结果

image.png

附件

nginx-1.24.0.zip

PS:附件是编译好的压缩包,解压即用,本地测试可用,但没有稳定性和性能测试,如有问题,请联系我!欢迎试用!