Using Apache Web Server with Jboss AS 7
In real-world projects, it's common to find Apache web server as a front door to your application server. The advantages of such an architecture are as follows:
• Speed: Apache is generally faster at serving static content than
JBoss Web server.
• Security: The application server, which contains sensitive data, can then be
placed in a protected area and, from a security point of view, you only need
to worry about the Apache server. Essentially, Apache becomes a smart
proxy server.
• Load balancing and clustering. By using Apache as a frontend you
can handle traffic to multiple JBoss Web server instances. If one of your
JBoss AS fails, the communication transparently continues to another
node in the cluster.
Connecting Apache and JBoss AS can be done by means of several libraries: in the past, most projects have adopted either Tomcat's mod_jk library or Apache's mod_proxy libraries. Because the installation of either mod_jk or mod_proxy does not differ from earlier AS releases, we will just include a quick setup guide for your reference.
If, however, you are planning to set up a high-performance, dynamic cluster of web servers, we suggest you migrate to the newer mod_cluster API.
Since Apache 1.3, there's support for an optional module, named mod_proxy, that configures Apache to act as a proxy server. This can be used to forward requests for particular web applications such as Tomcat or JBoss, without having to configure a web connector such as mod_jk.
So, mod_proxy just requires including the following directives in your Apache's httpd.conf file:
LoadModule proxy_module modules/mod_proxy.so
Then, include two directives in your httpd.conf file for each web application that you wish to forward to JBoss AS. For example, to forward an application at context path /myapp:
ProxyPass /myapp http://localhost:8080/myapp
ProxyPassReverse /myapp http://localhost:8080/myapp
This tells Apache to forward URLs of the form http://localhost/myapp/* to the JBoss HTTP connector listening on port 8080.
Apache's mod_proxy is TCP-based and uses the HTTP, so you don't need to add anything else in your JBoss configuration. By definition, this is the simplest way to put Apache in front of JBoss, but also the slowest way to do it .
In Apache 2.2, there's support for another module, named mod_proxy ajp, which can be used in much the same way as mod_proxy. However, it uses AJP protocol to proxy Apache requests to JBoss AS. In order to use it, add the following directive to your Apache configuration:
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
Then, enable proxy pass to JBoss AS with this directive:
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
Here, we are simply redirecting all traffic ("/") to the web server listening on localhost at port 8009.
Since mod_proxy_ajp runs on a dedicated port, you have to activate it on your
JBoss side:
<subsystem xmlns="urn:jboss:domain:web:1.1">
<connector name="http" protocol="HTTP/1.1" socket-binding="http" scheme="http"/>
<connector name="AJP" protocol="AJP/1.3" socket-binding="ajp" />
<virtual-server name="localhost">
<alias name="example.com"/>
</virtual-server>
</subsystem>
. . . . . .
<socket-binding-group name="standard-sockets" default-interface="default">
<socket-binding name="http" port="8080"/>
<socket-binding name="ajp" port="8009"/>
. . . .
</socket-binding-group>