How does nginx use third-party modules to check back-end servers
This article mainly explains "how nginx uses third-party modules to check back-end servers". The explanation in this article is simple and clear and easy to learn and understand. please follow the editor's ideas to study and learn "how nginx uses third-party modules to check back-end servers".
As we all know, the front end uses nginx as a reverse proxy. If the back-end server goes down, nginx cannot remove the real server from the upstream, so there will be requests forwarded to the back-end real server. Although nginx can enable proxy_next_upstream in the localtion to solve the error page returned to the user, this will forward the request to this server and then to another server. This is a waste of forwarding, this time using the nginx fast nginx_upstream_check_module developed with Taobao technical team to check the health status of the rear realserver. If the back-end server is not available, all requests will not be forwarded to this server.
First of all, go here to download the nginx module https://github.com/yaoweibin/nginx_upstream_check_module.
Here is the installation of the module patched nginx
$wget http://nginx.org/download/nginx-1.10.3.tar.gz
$tar-xzvf nginx-1.10.3.tar.gz
$cd nginx-1.10.3/
$patch-p1 < / path/to/nginx_http_upstream_check_module/check.patch
Note: due to the update of nginx version, the patch is check_1.7.2+.patch for nginx version 1.7.2 or above.
. / configure-add-module=/path/to/nginx_http_upstream_check_module
$make
$make install
Then add the health check to upstream in the nginx.conf configuration file, as follows:
Upstream linuxyan {
Server 192.168.0.21:80
Server 192.168.0.22:80
Check interval=3000 rise=2 fall=5 timeout=1000
}
Let me explain the following sentence: the interval between interval detection (in milliseconds); if two rsie requests are normal, marking the status of this realserver as up,fall means that if all five requests have failed, the status of marking this realserver is down;timeout as timeout (in milliseconds). You can add a page to view the realserver status in the server section.
Location / nstatus {
Check_status
Access_log off
# allow SOME.IP.ADD.RESS
# deny all
}
At this time, open the nstatus page and you can see the current realserver status.
As shown below:
1. When both realserver are normal
2. In the case of a realserver failure
Thank you for your reading, the above is the content of "how nginx uses third-party modules to check back-end servers". After the study of this article, I believe you have a deeper understanding of how nginx uses third-party modules to check back-end servers, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!