mod_proxy_ajp.html.en revision 96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end This file is generated from xml source: DO NOT EDIT
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<title>mod_proxy_ajp - Apache HTTP Server Version 2.5</title>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<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" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<script src="/style/scripts/prettify.min.js" type="text/javascript">
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<link href="/images/favicon.ico" rel="shortcut icon" /></head>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<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>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.5</a> > <a href="./">Modules</a></div>
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen<p><span>Available Languages: </span><a href="/en/mod/mod_proxy_ajp.html" title="English"> en </a> |
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<a href="/ja/mod/mod_proxy_ajp.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a></p>
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>AJP support module for
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen<code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code></td></tr>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>proxy_ajp_module</td></tr>
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_proxy_ajp.c</td></tr></table>
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun <p>This module <em>requires</em> the service of <code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code>. It provides support for the
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <code>Apache JServ Protocol version 1.3</code> (hereafter
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <p>Thus, in order to get the ability of handling <code>AJP13</code>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end protocol, <code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code> and
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <code class="module"><a href="/mod/mod_proxy_ajp.html">mod_proxy_ajp</a></code> have to be present in the server.</p>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <p>Do not enable proxying until you have <a href="mod_proxy.html#access">secured your server</a>. Open proxy
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end servers are dangerous both to your network and to the Internet at
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end large.</p>
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi<div id="quickview"><h3 class="directives">Directives</h3>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony<p>This module provides no
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony directives.</p>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<li><img alt="" src="/images/down.gif" /> <a href="#usage">Usage</a></li>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<li><img alt="" src="/images/down.gif" /> <a href="#env">Environment Variables</a></li>
316f02e3836836c82e19019ff23f90a7ebc65289nilgun<li><img alt="" src="/images/down.gif" /> <a href="#overviewprotocol">Overview of the protocol</a></li>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<li><img alt="" src="/images/down.gif" /> <a href="#basppacketstruct">Basic Packet Structure</a></li>
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen<li><img alt="" src="/images/down.gif" /> <a href="#rpacetstruct">Request Packet Structure</a></li>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<li><img alt="" src="/images/down.gif" /> <a href="#resppacketstruct">Response Packet Structure</a></li>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<li><code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code></li>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<li><a href="/env.html">Environment Variable documentation</a></li>
b43f840409794ed298e8634f6284741f193b6c4ftakashi</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd <p>This module is used to reverse proxy to a backend application server
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd (e.g. Apache Tomcat) using the AJP13 protocol. The usage is similar to
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf an HTTP reverse proxy, but uses the <code>ajp://</code> prefix:</p>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <div class="example"><h3>Simple Reverse Proxy</h3><pre class="prettyprint lang-config">ProxyPass /app ajp://backend.example.com:8009/app</pre>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <div class="example"><h3>Balancer Reverse Proxy</h3><pre class="prettyprint lang-config"><Proxy balancer://cluster>
623eebe956d9c2d6d073ed3eae855b56030b40e9noodl BalancerMember ajp://app1.example.com:8009 loadfactor=1
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end BalancerMember ajp://app2.example.com:8009 loadfactor=2
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end ProxySet lbmethod=bytraffic
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end</Proxy>
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe <p>Note that usually no
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe <code class="directive"><a href="/mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code>
65a611af7093423efb91e5794b8887a527d4cf63trawick directive is necessary. The AJP request includes the original host
65a611af7093423efb91e5794b8887a527d4cf63trawick header given to the proxy, and the application server can be expected
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end to generate self-referential headers relative to this host, so no
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end rewriting is necessary.</p>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <p>The main exception is when the URL path on the proxy differs from that
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end backend. In this case, a redirect header can be rewritten relative to the
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end original host URL (not the backend <code>ajp://</code> URL), for
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end example:</p>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <div class="example"><h3>Rewriting Proxied Path</h3><pre class="prettyprint lang-config">ProxyPass /apps/foo ajp://backend.example.com:8009/foo
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endProxyPassReverse /apps/foo http://www.example.com/foo</pre>
f3ec420152ca921e4c1ce77782f51b53f659018dnd <p>However, it is usually better to deploy the application on the backend
08cf4a15275e4cb65a424b3a1db5410bfb51085cjim server at the same path as the proxy rather than to take this approach.
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrin</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen<h2><a name="env" id="env">Environment Variables</a></h2>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <p>Environment variables whose names have the prefix <code>AJP_</code>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end are forwarded to the origin server as AJP request attributes
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end (with the AJP_ prefix removed from the name of the key).</p>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
7906201913b68fe78b9d6a22ab33bf21d82c490eminfrin<h2><a name="overviewprotocol" id="overviewprotocol">Overview of the protocol</a></h2>
7906201913b68fe78b9d6a22ab33bf21d82c490eminfrin <p>The <code>AJP13</code> protocol is packet-oriented. A binary format
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end was presumably chosen over the more readable plain text for reasons of
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen performance. The web server communicates with the servlet container over
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen TCP connections. To cut down on the expensive process of socket creation,
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end the web server will attempt to maintain persistent TCP connections to the
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end servlet container, and to reuse a connection for multiple request/response
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end cycles.</p>
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier <p>Once a connection is assigned to a particular request, it will not be
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd used for any others until the request-handling cycle has terminated. In
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end other words, requests are not multiplexed over connections. This makes
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf for much simpler code at either end of the connection, although it does
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end cause more connections to be open at once.</p>
f3ec420152ca921e4c1ce77782f51b53f659018dnd <p>Once the web server has opened a connection to the servlet container,
f3ec420152ca921e4c1ce77782f51b53f659018dnd the connection can be in one of the following states:</p>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <li> Idle <br /> No request is being handled over this connection. </li>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <li> Assigned <br /> The connection is handling a specific request.</li>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <p>Once a connection is assigned to handle a particular request, the basic
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end request information (e.g. HTTP headers, etc) is sent over the connection in
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end a highly condensed form (e.g. common strings are encoded as integers).
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end Details of that format are below in Request Packet Structure. If there is a
5effc8b39fae5cd169d17f342bfc265705840014rbowen body to the request <code>(content-length > 0)</code>, that is sent in a
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end separate packet immediately after.</p>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <p>At this point, the servlet container is presumably ready to start
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen processing the request. As it does so, it can send the
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen following messages back to the web server:</p>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <li>SEND_HEADERS <br />Send a set of headers back to the browser.</li>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <li>SEND_BODY_CHUNK <br />Send a chunk of body data back to the browser.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <li>GET_BODY_CHUNK <br />Get further data from the request if it hasn't all
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end been transferred yet. This is necessary because the packets have a fixed
2704de98885368683621b01c8f8f4e4b01557611takashi maximum size and arbitrary amounts of data can be included the body of a
2704de98885368683621b01c8f8f4e4b01557611takashi request (for uploaded files, for example). (Note: this is unrelated to
2704de98885368683621b01c8f8f4e4b01557611takashi HTTP chunked transfer).</li>
b43f840409794ed298e8634f6284741f193b6c4ftakashi <li>END_RESPONSE <br /> Finish the request-handling cycle.</li>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <p>Each message is accompanied by a differently formatted packet of data.
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi See Response Packet Structures below for details.</p>
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi<h2><a name="basppacketstruct" id="basppacketstruct">Basic Packet Structure</a></h2>
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi <p>There is a bit of an XDR heritage to this protocol, but it differs
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi in lots of ways (no 4 byte alignment, for example).</p>
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier <p>Byte order: I am not clear about the endian-ness of the individual
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier bytes. I'm guessing the bytes are little-endian, because that's what
e60187855fd0488f48f37e88acde742754308d39rbowen XDR specifies, and I'm guessing that sys/socket library is magically
04bab87733a0e93a926e82311c85cd8ac06a032fnd making that so (on the C side). If anyone with a better knowledge of
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end socket calls can step in, that would be great.</p>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <p>There are four data types in the protocol: bytes, booleans,
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end integers and strings.</p>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <dd>A single byte, <code>1 = true</code>, <code>0 = false</code>.
5effc8b39fae5cd169d17f342bfc265705840014rbowen Using other non-zero values as true (i.e. C-style) may work in some places,
5effc8b39fae5cd169d17f342bfc265705840014rbowen but it won't in others.</dd>
a610901168de82df5fc5d99b8759fd80e0f70aeasf <dd>A number in the range of <code>0 to 2^16 (32768)</code>. Stored in
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end 2 bytes with the high-order byte first.</dd>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <dd>A variable-sized string (length bounded by 2^16). Encoded with
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end the length packed into two bytes first, followed by the string
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end (including the terminating '\0'). Note that the encoded length does
438b4817913a5ff55d9cad4c7ddf133330b4466ejim <strong>not</strong> include the trailing '\0' -- it is like
438b4817913a5ff55d9cad4c7ddf133330b4466ejim <code>strlen</code>. This is a touch confusing on the Java side, which
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi is littered with odd autoincrement statements to skip over these
e5ce3ac0e9b720c0fa23782e29168a0810697fdetakashi terminators. I believe the reason this was done was to allow the C
604c89126c27104f659d7a51b0113e3bd435faf8fielding code to be extra efficient when reading strings which the servlet
50cb7e2b30597f481fee57bac945190f06ebcc58jorton container is sending back -- with the terminating \0 character, the
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end C code can pass around references into a single buffer, without copying.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end if the \0 was missing, the C code would have to copy things out in order
4126704c4950bfd46d32ad54e3b106ac6d868a73sf to get its notion of a string.</dd>
0a69d9bb491d9810892a9949c01403a1de3c7ac2nd <p>According to much of the code, the max packet size is <code>
2544c1693130c0a3106f2ff2c0ef7e3cf0a228e0jim 8 * 1024 bytes (8K)</code>. The actual length of the packet is encoded in
245eb3a84b8bc2b350c3a39ba2599444d443b50ajim the header.</p>
94cfb5d816f18c39adb74a03b6502ab73e35a73bnilgun <p>Packets sent from the server to the container begin with
94cfb5d816f18c39adb74a03b6502ab73e35a73bnilgun <code>0x1234</code>. Packets sent from the container to the server
9652bc3a93433d52f80579062986ead2afe0d11fsf begin with <code>AB</code> (that's the ASCII code for A followed by the
5f4e50966b2b9b58436a1651cbe588d1b595657ewrowe ASCII code for B). After those first two bytes, there is an integer
11495c9f0bd33e51a25b4d532beadfbcf9b944a3nilgun (encoded as above) with the length of the payload. Although this might
11495c9f0bd33e51a25b4d532beadfbcf9b944a3nilgun suggest that the maximum payload could be as large as 2^16, in fact, the
5f4e50966b2b9b58436a1651cbe588d1b595657ewrowe code sets the maximum to be 8K.</p>
79b024b81f6bb3c44dce77a7552191daf8b522d2jim <th colspan="6"><em>Packet Format (Server->Container)</em></th>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun <th colspan="6"><em>Packet Format (Container->Server)</em></th>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end <p>For most packets, the first byte of the payload encodes the type of
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end message. The exception is for request body packets sent from the server to
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen the container -- they are sent with a standard packet header (<code>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end 0x1234</code> and then length of the packet), but without any prefix code
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end after that.</p>
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen <p>The web server can send the following messages to the servlet
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen container:</p>
If there is no more data in the body (i.e. the servlet container is
<p><span>Available Languages: </span><a href="/en/mod/mod_proxy_ajp.html" title="English"> en </a> |
<a href="/ja/mod/mod_proxy_ajp.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a></p>
</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&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>
var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_proxy_ajp.html';
if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
d.write('<div id="comments_thread"><\/div>');
var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
(d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
<p class="apache">Copyright 2014 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>
<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[//><!--