How to Compile Nginx and Tengine with Health‑Check Modules for Enterprise Load Balancing
This guide walks through installing and compiling Nginx and its Alibaba‑derived fork Tengine, adding the echo‑nginx module, configuring health‑check directives, testing the setup with sample URLs, and explains Nginx upstream fault‑tolerance mechanisms for production environments.
Nginx is a lightweight web server and reverse‑proxy widely used for its low memory usage, fast startup, and high concurrency.
Tengine, an Alibaba open‑source project derived from Nginx, integrates many enterprise features and is compiled from the same Nginx version.
1. Basic Knowledge
Nginx is commonly used for reverse proxy, load balancing, and as a caching server.
The community (open‑source) version is most widely used in internet companies.
Recent Nginx releases support TCP load balancing via the stream module, enabling proxy of services like MySQL.
This article compares Nginx and Tengine from a load‑balancer perspective, covering compilation, installation, and health‑check modules.
2. Compile and Install Nginx
(1) Create a non‑root user
[root@laohan-nginx-test nginx-1.17.4]# groupadd www
[root@laohan-nginx-test nginx-1.17.4]# useradd -g www www(2) Compile Nginx
Version information:
[root@laohan-nginx-test ~]# ls -lhrt /opt/nginx-1.17.4.tar.gz
-rw-r--r-- 1 root root 1011K Sep 2423:13 /opt/nginx-1.17.4.tar.gzConfigure parameters:
./configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-threads(3) Install Nginx
[root@laohan-nginx-test nginx-1.17.4]# make && make install ; echo $?3. Install echo‑nginx‑module
The echo‑nginx‑module can output custom information, useful for simple APIs or debugging.
(1) Module source
https://github.com/openresty/echo-nginx-module#compatibility(2) Download and extract
wget -c https://github.com/openresty/echo-nginx-module/archive/master.zip
unzip master.zip(3) Re‑compile Nginx with the module
./configure --prefix=/usr/local/nginx --user=www --group=www \
--with-http_ssl_module --with-http_stub_status_module \
--with-http_realip_module --with-threads \
--add-module=../echo-nginx-module-master/; echo $?(4) Install
[root@laohan-nginx-test nginx-1.17.4]# make && make install ; echo $?4. Test echo Module
(1) Add test locations to nginx.conf
location /hello {
default_type 'text/plain';
return 200 'hello!';
}
location /hello_echo {
default_type 'text/plain';
echo "hello, echo!";
}Access URLs:
http://182.61.183.108/laohan
http://182.61.183.108/laohan_echoResults:
hello,laohan
hello, laohan_echo5. Install Tengine
(1) Download
wget -c http://tengine.taobao.org/download/tengine-2.3.2.tar.gz
Saving to: ‘tengine-2.3.tar.gz’(2) Extract tar xf tengine-2.3.2.tar.gz (3) Configure
./configure --prefix=/usr/local/tengine ; echo $?(4) Compile and install make && make install ; echo $? (5) Verify installation
/usr/local/tengine/sbin/nginx -t
nginx: the configuration file /usr/local/tengine/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/tengine/conf/nginx.conf test is successful6. Nginx Upstream Fault‑Tolerance
(1) Failure detection – Nginx marks a node as failed on connection‑refused or timeout; HTTP error codes are counted only when proxy_next_upstream is configured (404 is ignored).
(2) Failure and recovery triggers – max_fails and fail_timeout control when a node is marked down and when it is probed again.
(3) Full‑node failure handling – If all nodes are down, Nginx re‑enables them for probing; the first successful node is used, otherwise a 502 is returned.
7. Conclusion
Health‑check is a core load‑balancer feature; Tengine bundles it directly, while the open‑source Nginx can use third‑party modules such as ngx_http_upstream_check_module. Deploying these modules in production and testing thoroughly is recommended to avoid routing traffic to failed back‑ends.
tengine‑2.3.1 adds the ngx_http_upstream_check_module . It must be compiled with --add-module=./modules/ngx_http_upstream_check_module/ to enable health checks; otherwise configuration will report a syntax error.
Option
Description
interval
Interval between health‑check packets sent to the backend.
fall (fall_count)
Number of consecutive failures after which the server is considered down.
rise (rise_count)
Number of consecutive successes after which the server is considered up.
timeout
Timeout for the health‑check request.
default_down
Initial state of the server; true means it starts as down.
type
Type of health‑check packet (tcp, ssl_hello, http, mysql, ajp, port).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
