<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"><channel><title>Disruptive Library Technology Jester &#187; httpd</title> <atom:link href="http://dltj.org/tag/httpd/feed/" rel="self" type="application/rss+xml" /><link>http://dltj.org</link> <description>We&#039;re Disrupted, We&#039;re Librarians, and We&#039;re Not Going to Take It Anymore</description> <lastBuildDate>Mon, 06 Feb 2012 20:04:22 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <cloud domain='dltj.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' /> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/us/</creativeCommons:license> <item><title>Fronting Tomcat with Apache HTTPD to Remove Ports and Context Paths</title><link>http://dltj.org/article/apache-httpd-and-tomcat/</link> <comments>http://dltj.org/article/apache-httpd-and-tomcat/#comments</comments> <pubDate>Thu, 20 Sep 2007 02:31:33 +0000</pubDate> <dc:creator>Peter Murray</dc:creator> <category><![CDATA[Raw Technology]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[howto]]></category> <category><![CDATA[httpd]]></category> <category><![CDATA[tomcat]]></category> <category><![CDATA[usability]]></category> <category><![CDATA[web development]]></category><guid isPermaLink="false">http://dltj.org/2007/09/apache-httpd-and-tomcat/</guid> <description><![CDATA[In this How-To guide, I show a combination of software and configuration to clean up URLs by removing the port numbers of the Java servlet engine (Tomcat) and the context path of the application. The goal is to create &#8220;cool &#8230; <a href="http://dltj.org/article/apache-httpd-and-tomcat/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<abbr class="unapi-id ignore noPrint" title="http://dltj.org/2007/09/apache-httpd-and-tomcat/"></abbr><p>In this How-To guide, I show a combination of software and configuration to clean up URLs by removing the port numbers of the Java servlet engine (Tomcat) and the context path of the application.  The goal is to create &#8220;<a href="http://www.w3.org/Provider/Style/URI" title="Hypertext Style: Cool URIs don't change.">cool URLs</a>&#8221; that are are short (removing the unnecessary context path) and follow conventions (using the default port &#8220;80&#8243; rather than &#8220;8080&#8243;).  OhioLINK also uses a custom access control module &#8212; built for Apache HTTPD &#8212; which makes the fronting of Apache HTTPD for Tomcat even more desirable.</p><p><h2>Requirement</h2><br />We&#8217;re making use of the latest line of development for the Apache HTTPD series: <a href="http://httpd.apache.org/docs/2.2/" title="Apache HTTPD 2.2.x documentation">version 2.2.x</a>.  The inclusion of <a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html" title="Apache HTTPD mod_proxy_ajp documentation">mod_proxy_ajp</a> &#8212; replacing the custom &#8220;mod_jk&#8221; with a module that extends the httpd proxy engine &#8212; in the latest major release of HTTPD makes our task much easier.  This solution also uses HTTPD&#8217;s mod_rewrite and an add-on module called <a href="http://apache.webthing.com/mod_proxy_html/" title="mod_proxy_html Apache HTTPD module homepage">mod_proxy_html</a>.  No additions or changes are needed to the stock Tomcat installation.</p><p><h2>The Plan</h2><br />There are two overall tasks that we&#8217;re going to ask the HTTPD server to do.  First, receive the incoming HTTP request and proxy it to the Tomcat servlet engine using the AJP protocol.  Second, rewrite the URL paths of the headers and the X/HTML body from the Tomcat servlet engine to eliminate any instances of the context path.  In a visual sense, what we are trying to is rewrite the path so it can be processed by Tomcat (the green box) then remove the extraneous parts of the path in the resulting headers and X/HTML (the red box):</p><table cellpadding="2" cellspacing="0"><tr><td align="right"><i>Public Request URLs:&nbsp;&nbsp;</i></td><td colspan="2" align="right">http://e.com</td><td colspan="2">/remaining/path?and=params</td></tr><tr><td align="right"><i>URLs sent to Tomcat:&nbsp;&nbsp;</i></td><td>http://e.com</td><td style="background-color: #FFFFCC; padding-right: 0; margin-right: 0; border-left: 1px solid green; border-top: 1px solid green; border-bottom: 1px solid green;">:8080</td><td style="background-color: #FFFFCC; padding-left: 0; margin-left: 0; border-right: 1px solid green; border-top: 1px solid green; border-bottom: 1px solid green;">/context_path</td><td>/remaining/path?and=params</td></tr><tr><td align="right"><i>URLs as output by Tomcat:&nbsp;&nbsp;</i></td><td>http://e.com</td><td style="background-color: #FFFFCC; padding-right: 0; margin-right: 0; border-left: 1px solid red; border-top: 1px solid red; border-bottom: 1px solid red;">:8080</td><td style="background-color: #FFFFCC; padding-left: 0; margin-left: 0; border-right: 1px solid red; border-top: 1px solid red; border-bottom: 1px solid red;">/context_path</td><td>/next/page</td></tr><tr><td align="right"><i>URLs as seen by browser:&nbsp;&nbsp;</i></td><td colspan="2" align="right">http://e.com</td><td colspan="2">/next/page</td></tr></table><p>The first half of this problem, modifying a request as they come into the Apache HTTPD server, will be handled by a <a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html" title="Apache HTTPD mod_rewrite documentation">mod_rewrite</a> rule that rewrites the request to something Tomcat can understand then internally redirects it Tomcat via the AJP proxy.  (Note that we are not using simply <a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass" title="'ProxyPass' directive in HTTPD mod_proxy documentation">ProxyPass</a> here because we want to send the request through the AJP interface to the Tomcat server, and <a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule" title="'RewriteRule' directive in HTTPD mod_rewrite documentation">RewriteRule</a> allows us to do that with a <code>[P]</code> flag at the end of the RewriteRule line.)  The second uses a combination of <a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse" title="'ProxyPassReverse' directive in HTTPD mod_proxy documentation">ProxyPassReverse</a> (a part of Apache-supplied mod_proxy extension that adjusts the URL in the Location, Content-Location and URI headers), <a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreversecookiepath" title="'ProxyPassReverseCookiePath' directive in HTTPD mod_proxy documentation">ProxyPassReverseCookiePath</a> (also a part of the Apache-supplied mod_proxy extension; it rewrites the path string in Set-Cookie headers), and <a href="http://apache.webthing.com/mod_proxy_html/config.html" title="mod_proxy_html configuration documentation">ProxyHTMLURLMap</a> (from mod_proxy_html, a third-party extension that rewrites URLs inside X/HTML documents).</p><p><h2>Preparations</h2><br />The &#8216;mod_proxy_html&#8217; extension is likely new to your Apache HTTPD installation, so we need to download the source, compile it, and move it into the proper directory.  Fortunately, this is rather straight forward:</p><div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #ff0000;">'http://apache.webthing.com/mod_proxy_html/mod_proxy_html-2.5.2.c'</span>
apxs <span style="color: #660033;">-c</span> -I<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>libxml2 <span style="color: #660033;">-i</span> mod_proxy_html-2.5.2.c</pre></div></div><p>Note that we are not using the mod_proxy_html author&#8217;s 3.0 version here.  In my set-up, the 3.0 version was causing Apache HTTPD to dump core on <em>every</em> request (whether proxied or not), and the prior release works just fine for our purposes.  The <code>apxs</code> line will compile, link, and copy the resulting library to the Apache modules directory for us.</p><p><h2>The Configuration</h2><br />This is the contents a &#8216;tomcat-proxy.conf&#8217; file that is placed in the &#8216;conf.d&#8217; directory of the Apache HTTPD configuration directory (most likely <code>/etc/httpd/conf.d/tomcat-proxy.conf</code>, although your installation may vary).</p><div class="wp_syntax"><div class="code"><pre class="config" style="font-family:monospace;">#
#  Information about 'mod_proxy_html' can be found at 
#   http://apache.webthing.com/mod_proxy_html/
LoadFile    /usr/lib/libxml2.so
LoadModule  proxy_html_module    modules/mod_proxy_html-2.5.2.so
&nbsp;
# DON'T TURN ProxyRequests ON!  Bad things will happen
# http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#access
# http://www.akadia.com/services/prevent_abuse_proxy.html
ProxyRequests off
&nbsp;
# Necessary to have mod_proxy_html do the rewriting
RequestHeader      unset  Accept-Encoding
&nbsp;
# Rewrite the URLs to proxy (&quot;[P]&quot;) into the Tomcat server
RewriteEngine     on
RewriteRule ^(/.*)      ajp://localhost:8009/context_path/$1    [P]
&nbsp;
# Be prepared to rewrite the HTML/CSS files as they come back
# from Tomcat
SetOutputFilter proxy-html
&nbsp;
# Rewrite JavaScript and CSS files in addition to HTML files
ProxyHTMLExtended on
&nbsp;
# Output Strict XHTML (add &quot;Legacy&quot; to the end of the line below
# to output Transitional XHTML)
ProxyHTMLDoctype XHTML 
&nbsp;
# Rewrite HTTP headers and HTML/CSS links for everything else
ProxyPassReverse /context_path/ /
ProxyPassReverseCookiePath /context_path/ /
ProxyHTMLURLMap /context_path/ /</pre></div></div><p>That&#8217;s pretty much all there is to it.  You should note that mod_proxy_html, like any HTML scraper, requires modestly well-formed X/HTML.  If the markup is bad, the output from mod_proxy_html is likely to be unpredictable.</p>]]></content:encoded> <wfw:commentRss>http://dltj.org/article/apache-httpd-and-tomcat/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> </channel> </rss>
<!-- Served from: dltj.org @ 2012-02-11 09:23:31 by W3 Total Cache -->
