]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_proxy_hcheck.html.en
docs: update
[apache] / docs / manual / mod / mod_proxy_hcheck.html.en
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
4 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
5 <!--
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7               This file is generated from xml source: DO NOT EDIT
8         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9       -->
10 <title>mod_proxy_hcheck - Apache HTTP Server Version 2.5</title>
11 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
12 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
13 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
14 <script src="../style/scripts/prettify.min.js" type="text/javascript">
15 </script>
16
17 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
18 <body>
19 <div id="page-header">
20 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
21 <p class="apache">Apache HTTP Server Version 2.5</p>
22 <img alt="" src="../images/feather.png" /></div>
23 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
24 <div id="path">
25 <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.5</a> &gt; <a href="./">Modules</a></div>
26 <div id="page-content">
27 <div id="preamble"><h1>Apache Module mod_proxy_hcheck</h1>
28 <div class="toplang">
29 <p><span>Available Languages: </span><a href="../en/mod/mod_proxy_hcheck.html" title="English">&nbsp;en&nbsp;</a></p>
30 </div>
31 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Dynamic health check of Balancer members (workers) for
32 <code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code></td></tr>
33 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
34 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>proxy_hcheck_module</td></tr>
35 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_proxy_hcheck.c</td></tr>
36 <tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>Available in Apache 2.4.21 and later</td></tr></table>
37 <h3>Summary</h3>
38
39     <p>This module provides for dynamic health checking of balancer
40         members (workers). This can be enabled on a worker-by-worker
41         basis. The health check is done independently of the
42         actual reverse proxy requests.</p>
43
44     <p>This module <em>requires</em> the service of <code class="module"><a href="../mod/mod_watchdog.html">mod_watchdog</a></code>.</p>
45
46 <div class="note"><h3>Parameters</h3>
47   <p>The health check mechanism is enabled via the use of additional
48         BalancerMember parameters, which are configured in the standard
49         way via <code class="directive"><a href="../mod/mod_proxy.html#proxypass">ProxyPass</a></code>:</p>
50
51   <p>A new BalancerMember status state (flag) is defined via this module: "<code>C</code>".
52      When the worker is taken offline due to failures as determined by the health
53      check module, this flag is set, and can be seen (and modified) via the
54      <code>balancer-manager</code>.</p>
55
56     <table>
57     <tr><th>Parameter</th>
58         <th>Default</th>
59         <th>Description</th></tr>
60     <tr><td>hcmethod</td>
61         <td>None</td>
62         <td>No dynamic health check performed. Choices are:
63                 <table>
64                         <tr><th>Method</th><th>Description</th><th>Note</th></tr>
65                         <tr><td>None</td><td>No dynamic health checking done</td><td /></tr>
66                         <tr><td>TCP</td><td>Check that a socket to the backend can be created: e.g. "are you up"</td><td /></tr>
67                         <tr><td>OPTIONS</td><td>Send an <code>HTTP OPTIONS</code> request to the backend</td><td>*</td></tr>
68                         <tr><td>HEAD</td><td>Send an <code>HTTP HEAD</code> request to the backend</td><td>*</td></tr>
69                         <tr><td>GET</td><td>Send an <code>HTTP GET</code> request to the backend</td><td>*</td></tr>
70
71                                 <tr><td colspan="3" /></tr>
72                                 <tr><td colspan="3">*: Unless <code>hcexpr</code> is used, a 2xx or 3xx HTTP status will be interpreted as <em>passing</em> the health check</td></tr>
73                 </table>
74         </td></tr>
75     <tr><td>hcpasses</td>
76         <td>1</td>
77         <td>Number of successful health check tests before worker is re-enabled</td></tr>
78     <tr><td>hcfails</td>
79         <td>1</td>
80         <td>Number of failed health check tests before worker is disabled</td></tr>
81     <tr><td>hcinterval</td>
82         <td>30</td>
83         <td>Period of health checks in seconds (e.g. performed every 30 seconds)</td></tr>
84     <tr><td>hcuri</td>
85         <td>&nbsp;</td>
86         <td>Additional URI to be appended to the worker URL for the health check.</td></tr>
87     <tr><td>hctemplate</td>
88         <td>&nbsp;</td>
89         <td>Name of template, created via <code class="directive">ProxyHCTemplate</code> to use for setting health check parameters for this worker</td></tr>
90     <tr><td>hcexpr</td>
91         <td>&nbsp;</td>
92         <td>Name of expression, created via <code class="directive">ProxyHCExpr</code>, used to check response headers for health.<br />
93             <em>If not used, 2xx thru 3xx status codes imply success</em></td></tr>
94     </table>
95 </div>
96
97 </div>
98 <div id="quickview"><h3>Topics</h3>
99 <ul id="topics">
100 <li><img alt="" src="../images/down.gif" /> <a href="#examples">Usage examples</a></li>
101 </ul><h3 class="directives">Directives</h3>
102 <ul id="toc">
103 <li><img alt="" src="../images/down.gif" /> <a href="#proxyhcexpr">ProxyHCExpr</a></li>
104 <li><img alt="" src="../images/down.gif" /> <a href="#proxyhctemplate">ProxyHCTemplate</a></li>
105 <li><img alt="" src="../images/down.gif" /> <a href="#proxyhctpsize">ProxyHCTPsize</a></li>
106 </ul>
107 <h3>Bugfix checklist</h3><ul class="seealso"><li><a href="https://www.apache.org/dist/httpd/CHANGES_2.4">httpd changelog</a></li><li><a href="https://bz.apache.org/bugzilla/buglist.cgi?bug_status=__open__&amp;list_id=144532&amp;product=Apache%20httpd-2&amp;query_format=specific&amp;order=changeddate%20DESC%2Cpriority%2Cbug_severity&amp;component=mod_proxy_hcheck">Known issues</a></li><li><a href="https://bz.apache.org/bugzilla/enter_bug.cgi?product=Apache%20httpd-2&amp;component=mod_proxy_hcheck">Report a bug</a></li></ul><h3>See also</h3>
108 <ul class="seealso">
109 <li><code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code></li>
110 <li><a href="#comments_section">Comments</a></li></ul></div>
111 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
112 <div class="section">
113 <h2><a name="examples" id="examples">Usage examples</a></h2>
114
115         
116     <p>The following example shows how one might configured health checking
117         for various backend servers:</p>
118
119         
120         <pre class="prettyprint lang-config">ProxyHCExpr ok234 {%{REQUEST_STATUS} =~ /^[234]/}
121 ProxyHCExpr gdown {%{REQUEST_STATUS} =~ /^[5]/}
122 ProxyHCExpr in_maint {hc('body') !~ /Under maintenance/}
123
124 &lt;Proxy balancer://foo&gt;
125   BalancerMember http://www.example.com/  hcmethod=GET hcexpr=in_maint hcuri=/status.php
126   BalancerMember http://www2.example.com/  hcmethod=HEAD hcexpr=ok234 hcinterval=10
127   BalancerMember http://www3.example.com/ hcmethod=TCP hcinterval=5 hcpasses=2 hcfails=3
128   BalancerMember http://www4.example.com/
129 &lt;/Proxy&gt;
130
131 ProxyPass "/" "balancer://foo"
132 ProxyPassReverse "/" "balancer://foo"</pre>
133
134
135 <p>In this scenario, <code>http://www.example.com/</code> is health checked by sending a <code>GET /status.php</code>
136 request to that server and seeing that the returned page does not include the string <em>Under maintenance</em>. If
137 it does, that server is put in health-check fail mode, and disabled. This dynamic check is performed
138 every 30 seconds, which is the default.</p>
139
140 <p><code>http://www2.example.com/</code> is checked by sending a simple <code>HEAD</code> request every
141 10 seconds and making sure that the response status is 2xx, 3xx or 4xx. <code>http://www3.example.com/</code> is checked
142 every 5 seconds by simply ensuring that the socket to that server is up. If the backend is marked as
143 "down" and it passes 2 health check, it will be re-enabled and added back into the load balancer.
144 It takes 3 back-to-back health check failures to disable the server and move it out
145 of rotation. Finally, <code>http://www4.example.com/</code> is
146 not dynamically checked at all.</p>
147
148 </div>
149 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
150 <div class="directive-section"><h2><a name="ProxyHCExpr" id="ProxyHCExpr">ProxyHCExpr</a> <a name="proxyhcexpr" id="proxyhcexpr">Directive</a></h2>
151 <table class="directive">
152 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Creates a named condition expression to use to determine health of the backend based on its response.</td></tr>
153 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ProxyHCExpr name {ap_expr expression}</code></td></tr>
154 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
155 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
156 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
157 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_proxy_hcheck</td></tr>
158 </table>
159     <p>The <code class="directive">ProxyHCExpr</code> directive allows
160        for creating a named condition expression that checks the response
161        headers of the backend server to determine its health. This named
162        condition can then be assigned to balancer members via the <code>hcexpr</code>
163        parameter</p>
164
165     <div class="example"><h3>ProxyHCExpr: Allow for 2xx/3xx/4xx as passing</h3><pre class="prettyprint lang-config">ProxyHCExpr ok234 {%{REQUEST_STATUS} =~ /^[234]/}
166 ProxyPass "/apps"     "http://backend.example.com/" hcexpr=ok234</pre>
167 </div>
168
169     <div class="note">
170     The <a href="../expr.html">expression</a> can use curly-parens ("{}") as
171     quoting deliminators in addition to normal quotes.
172     </div>
173
174     <p>If using a health check method (eg: <code>GET</code>) which results in a response
175     body, that body itself can be checked via <code>ap_expr</code> using the <code>hc()</code>
176     expression function, which is unique to this module.</p>
177
178     <p>In the following example, we send the backend a <code>GET</code> request
179     and if the response body contains the phrase <em>Under maintenance</em>,
180     we want to disable the backend.</p>
181
182     <div class="example"><h3>ProxyHCExpr: Checking response body</h3><pre class="prettyprint lang-config">ProxyHCExpr in_maint {hc('body') !~ /Under maintenance/}
183 ProxyPass "/apps"     "http://backend.example.com/" hcexpr=in_maint hcmethod=get hcuri=/status.php</pre>
184 </div>
185
186     <p><em>NOTE:</em> Since response body can quite large, it is best if used against specific status pages.</p>
187
188 </div>
189 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
190 <div class="directive-section"><h2><a name="ProxyHCTemplate" id="ProxyHCTemplate">ProxyHCTemplate</a> <a name="proxyhctemplate" id="proxyhctemplate">Directive</a></h2>
191 <table class="directive">
192 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Creates a named template for setting various health check parameters</td></tr>
193 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ProxyHCTemplate name parameter=setting &lt;...&gt;</code></td></tr>
194 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
195 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
196 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
197 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_proxy_hcheck</td></tr>
198 </table>
199     <p>The <code class="directive">ProxyHCTemplate</code> directive allows
200        for creating a named set (template) of health check parameters
201        that can then be assigned to balancer members via the <code>hctemplate</code>
202        parameter</p>
203
204     <div class="example"><h3>ProxyHCTemplate</h3><pre class="prettyprint lang-config">ProxyHCTemplate tcp5 hcmethod=tcp hcinterval=5
205 ProxyPass "/apps"     "http://backend.example.com/" hctemplate=tcp5</pre>
206 </div>
207
208
209 </div>
210 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
211 <div class="directive-section"><h2><a name="ProxyHCTPsize" id="ProxyHCTPsize">ProxyHCTPsize</a> <a name="proxyhctpsize" id="proxyhctpsize">Directive</a></h2>
212 <table class="directive">
213 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the total server-wide size of the threadpool used for the health check workers.</td></tr>
214 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ProxyHCTPsize &lt;size&gt;</code></td></tr>
215 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
216 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
217 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_proxy_hcheck</td></tr>
218 </table>
219     <p>If Apache httpd and APR are built with thread support, the health check
220        module will offload the work of the actual checking to a threadpool
221        associated with the Watchdog process, allowing for parallel checks.
222        The <code class="directive">ProxyHCTPsize</code> directive
223        determines the size of this threadpool. If set to <code>0</code>, no threadpool
224        is used at all, resulting in serialized health checks. The default size is 16.</p>
225
226     <div class="example"><h3>ProxyHCTPsize</h3><pre class="prettyprint lang-config">ProxyHCTPsize 32</pre>
227 </div>
228
229
230 </div>
231 </div>
232 <div class="bottomlang">
233 <p><span>Available Languages: </span><a href="../en/mod/mod_proxy_hcheck.html" title="English">&nbsp;en&nbsp;</a></p>
234 </div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
235 <script type="text/javascript"><!--//--><![CDATA[//><!--
236 var comments_shortname = 'httpd';
237 var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_proxy_hcheck.html';
238 (function(w, d) {
239     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
240         d.write('<div id="comments_thread"><\/div>');
241         var s = d.createElement('script');
242         s.type = 'text/javascript';
243         s.async = true;
244         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
245         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
246     }
247     else {
248         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
249     }
250 })(window, document);
251 //--><!]]></script></div><div id="footer">
252 <p class="apache">Copyright 2017 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
253 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
254 if (typeof(prettyPrint) !== 'undefined') {
255     prettyPrint();
256 }
257 //--><!]]></script>
258 </body></html>