<?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/"
	>

<channel>
	<title>biotext.org.uk &#187; apache</title>
	<atom:link href="http://biotext.org.uk/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://biotext.org.uk</link>
	<description>Not a typewriter</description>
	<lastBuildDate>Mon, 06 Sep 2010 12:44:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Connecting Apache to Tomcat: mod_jk</title>
		<link>http://biotext.org.uk/connecting-apache-to-tomcat-mod_jk/</link>
		<comments>http://biotext.org.uk/connecting-apache-to-tomcat-mod_jk/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 16:37:16 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://biotext.org.uk/?p=247</guid>
		<description><![CDATA[I spent yesterday afternoon trying to get Tomcat web apps served via Apache, since that decouples the public interfaces of our web services from their implementation &#8212; people don&#8217;t need to know when they hit a service that it&#8217;s running on a Tomcat server on port 8080. There&#8217;s a connector to allow this, mod_jk, but [...]]]></description>
			<content:encoded><![CDATA[<p>I spent yesterday afternoon trying to get Tomcat web apps served via Apache, since that decouples the public interfaces of our web services from their implementation &#8212; people don&#8217;t need to know when they hit a service that it&#8217;s running on a Tomcat server on port 8080. There&#8217;s a connector to allow this, <a href="http://tomcat.apache.org/connectors-doc/">mod_jk</a>, but it&#8217;s a bit of a pain to get working &#8212; it required changes to five different config files. So I&#8217;ve pasted the required changes here, hopefully this will be helpful.</p>
<p><span id="more-247"></span>The scenario is that there&#8217;s a site (<a title="FuncNet" href="http://funcnet.eu/">funcnet.eu</a>) which will be running as an Apache 2.2.3 virtual host on an existing server. Two paths on that site should be redirected to CXF webapps running on Tomcat 6.0.16 on the same physical box. Any requests outside those two directories should be handled by Apache itself. This lets us host a WordPress installation and Java apps/services on funcnet.eu in a seamless way.</p>
<p>So first, the server-wide Apache configuration, just to load the mod_jk library, in /etc/httpd/conf/httpd.conf :</p>
<pre>LoadModule jk_module modules/mod_jk.so</pre>
<p>Then we need to add some JK mounts to the funcnet.eu virtual server configuration in /etc/httpd/conf.d/virtual_hosts.conf , as well as some rewrite rules using mod_rewrite:</p>
<pre>&lt;VirtualHost *:80&gt;
    ServerName      www.funcnet.eu
    ServerAlias     funcnet.eu *.funcnet.eu funcnet.cathdb.info
    DocumentRoot    /var/www/virtual-hosts/funcnet.eu
    ErrorLog        logs/funcnet.eu/error_log
    CustomLog       logs/funcnet.eu/access_log common
    JkMount         /BioMiner-war local8009
    JkMount         /BioMiner-war/* local8009
    JkMount         /frontend-war local8009
    JkMount         /frontend-war/* local8009
    RewriteRule     ^/frontend/soap(.*)$    /frontend-war/services$1  [PT,QSA]
    RewriteRule     ^/frontend(.*)$         /frontend-war$1           [PT,QSA]
    RewriteRule     ^/biominer/soap(.*)$    /BioMiner-war/services$1  [PT,QSA]
    RewriteRule     ^/biominer(.*)$         /BioMiner-war$1           [PT,QSA]
&lt;/VirtualHost&gt;</pre>
<p>The idea of JkMount is that any request matching one of the URL patterns given will be handled by the &#8216;worker&#8217; specified, local8009 (see below). Anything not matching these patterns will be handled by Apache. I&#8217;m not sure if you really need the exact-match version as well as the wildcard version for each directory, but one or two examples I saw used this, one day I&#8217;ll test it but for now it can remain in cargo-cult territory. The rewrite rules are completely optional, they&#8217;re just there to shorten and neaten-up the URLs we publish.</p>
<p>Then we created a file called /etc/httpd/conf.d/jk.conf (alk .conf files in conf.d are automatically loaded by our Apache server):</p>
<pre>JkWorkersFile       /etc/httpd/conf/workers.properties
JkLogFile           /etc/httpd/logs/mod_jk.log
JkShmFile           /etc/httpd/logs/mod_jk.shm
JkLogLevel          info
JkLogStampFormat    "[%a %b %d %H:%M:%S %Y] "</pre>
<p>These should be pretty self-explanatory. Then finally (for Apache) we had to create /etc/httpd/conf/workers.properties as described in the previous file:</p>
<pre>worker.list=local8009
worker.local8009.type=ajp13
worker.local8009.host=localhost
worker.local8009.port=8009</pre>
<p>This sets up a single &#8216;worker&#8217; called local8009 which is an instance of Tomcat running on localhost. It communicates with Apache via the AJP/1.3 protocol on port 8009 &#8212; Apache uses this optimized binary protocol to talk to Tomcat as this is much more efficient than just proxying HTTP requests.</p>
<p>Finally, we had to add an AJP13 connector to our Tomcat server.xml (within the &lt;Service name=&#8221;Catalina&#8221;&gt; node) which listens on the port specified above:</p>
<pre>&lt;Connector
    port="8009" protocol="AJP/1.3" maxPostSize="-1" maxSavePostSize="-1"
    proxyName="funcnet.eu" proxyPort="80"/&gt;</pre>
<p>This disables a couple of maximum-size parameters (details <a title="Tomcat AJP docs" href="http://tomcat.apache.org/tomcat-6.0-doc/config/ajp.html">here</a>) and sets the hostname and port number that will be reported to applications invoked via AJP, should they request it. (I haven&#8217;t tried this yet though&#8230;)</p>
<p>I&#8217;m pretty happy with this setup as it lets us run a WordPress site in PHP on <a title="FuncNet" href="http://funcnet.eu/">funcnet.eu</a> and serve the Java web services off the same domain, along with any other static downloads we need. Hope the instructions are fairly clear, drop a comment if you get stuck. One thing worth noting is that you can raise the log level from &#8216;info&#8217; to &#8216;debug&#8217; in jk.conf to get more information in mod_jk.log if you need it. But this actually makes a log entry for every NON-proxied request to Apache (i.e. &#8220;couldn&#8217;t find a mapping for&#8230;&#8221;) so it&#8217;ll get very big very quickly.</p>
<p>EDIT: I&#8217;ve changed the rewrite rules from those given above as it appears CXF gets confused when you try to invoke a service endpoint (or its built-in WSDL rewriter) via a rewritten-and-then-proxied URL. So now the virtual host config for Apache looks like this:</p>
<pre>&lt;VirtualHost *:80&gt;
    ServerName      www.funcnet.eu
    ServerAlias     funcnet.eu *.funcnet.eu funcnet.cathdb.info
    DocumentRoot    /var/www/virtual-hosts/funcnet.eu
    ErrorLog        logs/funcnet.eu/error_log
    CustomLog       logs/funcnet.eu/access_log common
    JkMount         /BioMiner-war local8009
    JkMount         /BioMiner-war/* local8009
    JkMount         /frontend-war local8009
    JkMount         /frontend-war/* local8009
    RewriteEngine   on
    RewriteLog      /etc/httpd/logs/funcnet.eu/rewrite_log
    RewriteLogLevel 2
    RewriteRule     ^/soap/FrontEnd.wsdl$     /frontend-war/services/FrontEndService?wsdl [PT]
    RewriteRule     ^/soap/Geco.wsdl$         /BioMiner-war/services/GecoService?wsdl [PT]
    RewriteRule     ^/soap/Hippi.wsdl$        /BioMiner-war/services/HippiService?wsdl [PT]
    RewriteRule     ^/soap/CodaCath.wsdl$     /BioMiner-war/services/CodaCathService?wsdl [PT]
    RewriteRule     ^/soap/CodaPfam.wsdl$     /BioMiner-war/services/CodaPfamService?wsdl [PT]
&lt;/VirtualHost&gt;</pre>
<p>So now we just have permanent funcnet.eu/soap/&lt;servicename&gt;.wsdl URLs that serve the real WSDLs containing the SOAP endpoint addresses &#8212; which handily start with http://funcnet.eu/ because CXF&#8217;s WSDL rewriter detects what server the WSDL was requested <em>via</em> by looking in the query string.</p>
<p>Andrew.</p>
]]></content:encoded>
			<wfw:commentRss>http://biotext.org.uk/connecting-apache-to-tomcat-mod_jk/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
