Я собрал nginx 1.14 и nginx 1.16 c nginx_upstream_check_module из мастер ветки c помощью https://github.com/TinkoffCreditSystems/Nginx-builder
Конфиг Nginx-builder:
nginx_version: 1.14.2
output_package: rpm
modules:
- module:
name: nginx-module-vts
git_url: https://github.com/vozlt/nginx-module-vts.git
git_tag: v0.1.18
- module:
name: nginx_upstream_check_module
git_url: https://github.com/yaoweibin/nginx_upstream_check_module.git
git_branch: master
Для эмуляции сервиса использовал mockify. Конфиг mockify:
routes200.yaml:
---
- route: "/"
methods:
- GET
responses:
- uri: "/"
method: GET
statusCode: 200
body:
message: 200\n
routes503.yaml:
---
- route: "/"
methods:
- GET
responses:
- uri: "/"
method: GET
statusCode: 503
body:
message: 503\n
Конфиг nginx.conf:
user nginx;
worker_processes auto;
worker_rlimit_nofile 40960;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 1024;
multi_accept on;
}
http {
vhost_traffic_status_zone;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
#access_log off;
sendfile on;
tcp_nodelay on;
tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
}
Конфиг виртуального хоста:
upstream backend {
server 127.0.0.1:8002; # 200 http code
server 127.0.0.1:8003; # 200 http code
server 127.0.0.1:8004; # 200 http code
server 127.0.0.1:8005; # 200 http code
server 127.0.0.1:8006; # 503 http code
check interval=3000 rise=2 fall=5 timeout=1000 default_down=true type=http;
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 80;
server_name vhost1;
location / {
proxy_pass http://backend;
}
location /status {
check_status;
}
}
Запускаю проверку с помощью curl в цикле:
while true; do curl -i http://vhost1/; sleep 1; done
Получаю вот что:
200\nHTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 19 Nov 2019 12:50:05 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 5
Connection: keep-alive
200\nHTTP/1.1 503 Service Unavailable
Server: nginx/1.14.2
Date: Tue, 19 Nov 2019 12:50:06 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 5
Connection: keep-alive
503\nHTTP/1.1 503 Service Unavailable
Server: nginx/1.14.2
Date: Tue, 19 Nov 2019 12:50:07 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 5
Connection: keep-alive
Проверка модулей:
nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
configure arguments:
--prefix=/etc/nginx
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--modules-path=/usr/lib/nginx/modules
--error-log-path=/var/log/nginx/error.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/lock/nginx.lock
--http-log-path=/var/log/nginx/access.log
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
--with-debug
--user=nginx
--group=nginx
--with-pcre-jit
--with-compat
--with-file-aio
--with-threads
--with-stream
--with-cc-opt=
--with-ld-opt=
--add-module=/root/rpmbuild/SOURCES/modules/nginx-module-vts
--add-module=/root/rpmbuild/SOURCES/modules/nginx_upstream_check_module
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong
--param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC'
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'