# nginx_upstream_check_module **Repository Path**: zhaog/nginx_upstream_check_module ## Basic Information - **Project Name**: nginx_upstream_check_module - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-08-12 - **Last Updated**: 2024-11-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Name nginx_http_upstream_check_module - support upstream health check with Nginx Synopsis http { upstream cluster { # simple round-robin server 192.168.0.1:80; server 192.168.0.2:80; check interval=5000 rise=1 fall=3 timeout=4000; #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello; #check interval=3000 rise=2 fall=5 timeout=1000 type=http; #check_http_send "HEAD / HTTP/1.0\r\n\r\n"; #check_http_expect_alive http_2xx http_3xx; } server { listen 80; location / { proxy_pass http://cluster; } location /status { check_status; access_log off; allow SOME.IP.ADD.RESS; deny all; } } } Description Add the support of health check with the upstream servers. Directives check syntax: *check interval=milliseconds [fall=count] [rise=count] [timeout=milliseconds] [default_down=true|false] [type=tcp|http|ssl_hello|mysql|ajp|fastcgi]* default: *none, if parameters omitted, default parameters are interval=30000 fall=5 rise=2 timeout=1000 default_down=true type=tcp* context: *upstream* description: Add the health check for the upstream servers. The parameters' meanings are: * *interval*: the check request's interval time. * *fall*(fall_count): After fall_count check failures, the server is marked down. * *rise*(rise_count): After rise_count check success, the server is marked up. * *timeout*: the check request's timeout. * *default_down*: set initial state of backend server, default is down. * *port*: specify the check port in the backend servers. It can be different with the original servers port. Default the port is 0 and it means the same as the original backend server. * *type*: the check protocol type: 1. *tcp* is a simple tcp socket connect and peek one byte. 2. *ssl_hello* sends a client ssl hello packet and receives the server ssl hello packet. 3. *http* sends a http request packet, receives and parses the http response to diagnose if the upstream server is alive. 4. *mysql* connects to the mysql server, receives the greeting response to diagnose if the upstream server is alive. 5. *ajp* sends a AJP Cping packet, receives and parses the AJP Cpong response to diagnose if the upstream server is alive. 6. *fastcgi* send a fastcgi request, receives and parses the fastcgi response to diagnose if the upstream server is alive. check_http_send syntax: *check_http_send http_packet* default: *"GET / HTTP/1.0\r\n\r\n"* context: *upstream* description: If you set the check type is http, then the check function will sends this http packet to check the upstream server. check_http_expect_alive syntax: *check_http_expect_alive [ http_2xx | http_3xx | http_4xx | http_5xx ]* default: *http_2xx | http_3xx* context: *upstream* description: These status codes indicate the upstream server's http response is ok, the backend is alive. check_keepalive_requests syntax: *check_keepalive_requests num* default: *check_keepalive_requests 1* context: *upstream* description: The directive specifies the number of requests sent on a connection, the default vaule 1 indicates that nginx will certainly close the connection after a request. check_fastcgi_param Syntax: *check_fastcgi_params parameter value* default: see below context: *upstream* description: If you set the check type is fastcgi, then the check function will sends this fastcgi headers to check the upstream server. The default directive looks like: check_fastcgi_param "REQUEST_METHOD" "GET"; check_fastcgi_param "REQUEST_URI" "/"; check_fastcgi_param "SCRIPT_FILENAME" "index.php"; check_shm_size syntax: *check_shm_size size* default: *1M* context: *http* description: Default size is one megabytes. If you check thousands of servers, the shared memory for health check may be not enough, you can enlarge it with this directive. check_status syntax: *check_status [html|csv|json]* default: *none* context: *location* description: Display the health checking servers' status by HTTP. This directive should be set in the http block. You can specify the default display format. The formats can be `html`, `csv` or `json`. The default type is `html`. It also supports to specify the format by the request argument. Suppose your `check_status` location is '/status', the argument of `format` can change the display page's format. You can do like this: /status?format=html /status?format=csv /status?format=json At present, you can fetch the list of servers with the same status by the argument of `status`. For example: /status?format=html&status=down /status?format=csv&status=up Below it's the sample html page: