Saturday, March 26, 2011

Running Apache as front-end to JBoss with virtual hosts

I run several websites on JBoss on my home computer and use Apache as a front-end to redirect requests to the correct sites. Basically if you want your site to be accessible from as is without appending the web app context (e.g., you need to do this. This is also more secure as you can bind JBoss to localhost only and hide the jmx-console.

First of all, you should have defined your web-apps' contexts in their WEB-INF/jboss-web.xml files:

<?xml version="1.0" encoding="UTF-8"?>


Thats all what is needed from JBoss.

Next, you need to add the virtual host configs to Apache httpd.conf file. Example for a single website:

<VirtualHost *:80>
  ProxyPass / http://localhost:8080/mywebapp/
  ProxyPassReverse / http://localhost:8080/mywebapp/
  ProxyPreserveHost On
  ProxyPassReverseCookiePath / /
  ErrorLog logs/mysite-error_log
  CustomLog logs/mysite-access_log common

The thing with the proxypass and proxypassreverse directives is that it preserves the domain so you can handle cookies as is on JBoss side without any problems, and that sessions are tracked correctly.

No comments:

Post a Comment