Java 2 Ada - Tag JBoss2009-01-28T21:21:29+00:00Stephane Carrezurn:md5:d12e23c53b2436d6becce3d51ddbdf38AWAApache and JBoss integration with mod_rewrite and mod_proxyurn:md5:33e7ba562ef2ee6cb980fd29fd5ed0942009-01-28T21:21:29+00:002009-01-28T21:21:29+00:00Stephane CarrezApacheJ2EEJBossProxyRewrite
<div class="post-text"><p>The problem I wanted to solve was to be able to use the Apache URL rewrite before forwarding the request to a JBoss server. The Apache and JBoss were already integrated with mod_jk (<a href="/index.php?post/2008/04/13/12-deploying-a-j2ee-application-behind-an-apache-server-in-a-production-environment">Deploying a J2EE application behind an Apache server</a>). The URL rewriting rule does not work in that case (at least I was not able to make it work). I investigated the Apache mod_rewrite and its proxy configuration.</p><p>First, in your Apache host configuration you have to enable the Apache rewrite module. This is done by the RewriteEngine directive. To make sure that the server name is propagated to JBoss, you have to use the ProxyPreserveHost directive. If you don't do this, JBoss will receive 'localhost' as server name (ie, the servlet request <code>getServerName()</code> method will not return what you expect). You then define your rewrite rule and use the proxy forwarding mode indicated by [P].</p><pre><code> <VirtualHost *:80>
RewriteEngine On
ProxyPreserveHost On
RewriteRule ^/some-path/(.*)$ \
http://localhost:8080/web-app-deploy-name/$1 \[P\]
...
</VirtualHost>
</code></pre><p>You have to make sure the Apache modules are available, for this execute these commands:</p><pre><code> sudo a2enmod proxy proxy_http rewrite
</code></pre><p>Once your configuration files are ready, reload Apache configuration:</p><pre><code> sudo /etc/init.d/apache2 reload
</code></pre><p>That it!</p><p>This mod_rewrite and mod_proxy configuration is very powerful and easier to setup than mod_jk.</p></div>