Archive for the ‘ apache ’ Category

ColdFusion on JBoss with Apache Proxy

I won’t go heavily into the reasons why you would want to use Apache as your proxy to JBoss, but I’ll give some popular ones here so you can see if any of the areas interest you.

  1. You want to run PHP and ColdFusion on the same server with minimal headaches
  2. You want to host multiple domains on your JBoss instance
  3. You need to use complex URI rewriting rules for incoming requests
  4. You need to run IIS and JBoss on the same server
  5. You just need a solid, lightweight web server

The reasons I chose to use Apache to act as the web server for my JBoss servers were 1 and 2. I eventually needed to do a little bit of 3. I temporarily had to do number 4, and how easily I have been able to do all of this led me to believe number 5.

Preparing JBoss

The only thing you need to change on JBoss to have Apache act as a proxy to it is ensure that is it not listening on port 80 (which you may have set if it was acting as your web server). Read step 5 in my standalone primer article for instructions on how to change your HTTP port if you haven’t done this before.

Install Apache

I downloaded version 2.0.58 which works just fine for my purposes. However, by the time you read this article, there may be a much better and/or feature-rich version of Apache available. Just download the version you feel best suits your purposes based on your needs.

Configure Apache

Find the ‘Listen’ section of in the \Apache\conf\httpd.conf file and specify the IP address and port on which Apache is listening.

Listen <server ip address>:80

Next, you need to tell Apache where to direct traffic coming in on port 80 on that IP address. For this, we use Virtual Hosts.

NameVirtualHost <server ip address>:80

Now that Apache is prepared to accept request for multiple domain names, we need to set up each of those domains using the <virtualhost> tag. All you need to specify is the ServerName property, which the the base URL of the domain, and the ProxyPass property which simply tells Apache where to redirect the original request.

If your JBoss server is internal only and not public facing, you’ll have to use the IP address from Apache since that’s the designator for it.

<virtualhost>
    ServerName www.orbwave.com
    ProxyPass / http://{jboss server IP}:8080/
</virtualhost>

<virtualhost>
    ServerName www.fusioncube.net
    ProxyPass / http://{jboss server IP}:8080/
</virtualhost>

If you have both Apache and JBoss sitting on your public web server, you’ll need to use the domain name instead of the IP address.

<virtualhost>
    ServerName www.orbwave.com
    ProxyPass / http://www.orbwave.com:8080/
</virtualhost>

<virtualhost>
    ServerName www.fusioncube.net
    ProxyPass / http://www.fusioncube.net:8080/
</virtualhost>

Configure JBoss to accept requests for multiple domains

What you need to do is create a seperate Host configuration for the edach domain in the server definition file which is located at \jboss\server\default\deploy\jbossweb-tomcat55.sar\server.xml.

Open that file and you’ll see a Host configuration already for localhost. This is the default host meaning that all traffic directed via your web server port (8080) will be directed to your root application. This will be your default domain, meaning the one for which you don’t define a Host.

Now let’s create a new Host designation that will direct requests for two new domain names.

<Host name="domain2 {this can be whatever you want}" autoDeploy="false" deployOnStartup="false" deployXML="false">
    <Alias>www.second-domain-name.com</Alias>

    <Valve className="org.apache.catalina.valves.AccessLogValve"
        prefix="things" suffix=".log" pattern="common"
        directory="${jboss.server.home.dir}/log"/>

    <DefaultContext cookies="true" crossContext="true" override="true"/>
</Host>

<Host name="domain3 {this can be whatever you want}" autoDeploy="false" deployOnStartup="false" deployXML="false">
    <Alias>www.third-domain-name.com</Alias>

    <Valve className="org.apache.catalina.valves.AccessLogValve"
        prefix="things" suffix=".log" pattern="common"
        directory="${jboss.server.home.dir}/log"/>

    <DefaultContext cookies="true" crossContext="true" override="true"/>
</Host>

Define Virtual Hosts for Applications

The last step is to modify the jboss-web.xml file for each application. We’ve set up a brand new Host designation, so now each application can be set up as another root application, except now it sits in its own Host space rather than in the one set up for localhost.

So open up the jboss-web.xml file of the application that will be running for second-domain-name.com. Change the context-root definition to root (/) and then match it up with one of the Host entries you made in the server.xml file.

<jboss-web>
    <context-root>/</context-root>
    <virtual-host>domain2</virtual-host>
</jboss-web>

Similarly for another application that will be served for third-domain-name.com

<jboss-web>
    <context-root>/</context-root>
    <virtual-host>domain3</virtual-host>
</jboss-web>

All you need to do is start/restart your Jboss instance and request for both domain names will now be redirected to the appropriate application. Just be sure that you have made the requisite changes to your DNS records and they have propagated.

Apache Proxy to JBoss and IIS

Well, I finally had to enable some PHP sites on my servers, effectively ending my ColdFusion-only epoch. Getting IIS up and running alongside JBoss (or even JRun) turned out to be ridiculously easy with Apache. As was my experience with JBoss, the documentation from the vendor turned out to be somewhere between poor to adequate and I ended up relying almost completely on the examples and tutorials placed out by others on the Web.

Now that I think about it, it wasn’t “ridiculously” easy because I had a problem with IIS and JBoss attempting to listen on the same IP address even though I went into IIS and changed the configuration. Luckily this was a documented issue and I found the resolution easily (more info below).

Step 1 - Install Apache

I downloaded version 2.0.58 which works just fine for my purposes.

Apache Configuration

Find the ‘Listen’ section of in the \Apache\conf\httpd.conf file and specify the IP address and port on which Apache is listening.

Listen 192.168.1.200:80

Now, since I’m hosting multiple domains on my system, I need Apache’s virtual hosts to match up with each JBoss virtual host. You can read my article on hosting multiple domains with JBoss for more information on that. the first thing to do is tell Apache that this IP/Port will be using Named Virtual Hosts instead of IP Virtual Hosts.

NameVirtualHost 192.168.1.200:80

Now that Apache knows the it’s going to be accepting request for multiple domain names, we need to set up each of those domains using the <virtualhost> tag. All you need to specify is the ServerName property, which the the base URL of the domain, and the ProxyPass property which simply tells Apache where to redirect the original request.

<virtualhost>
ServerName www.orbwave.com
ProxyPass / http://www.orbwave.com:8080/
</virtualhost>

<virtualhost>
ServerName www.fusioncube.net
ProxyPass / http://www.fusioncube.net:8080/
</virtualhost>

JBoss Configuration

As you can see above, if you’ve got JBoss listening on port 80, it will conflict with Apache and you need to reset it to listen on port 8080. Then Apache redirects the request to port 8080 to be fulfilled by JBoss.

IIS Configuration

Now here’s the tricky part. IIS can’t listen to requests on the same IP address as Apache or it tries to hijack all requests by default. Therefore, you need two IP addresses to be assigned to the server accepting these HTTP requests. Two ways to do that:

  1. Install another network adapter, assign is a distinct, static IP address and plug it into the network.
  2. Assign another IP address to the network adapter you’re already using.

Now you have to disable socket pooling in IIS. You have to use a utility called Httpcfg.exe to disable it. This utility is found in the /Support/Tools folder on your Windows Server 2003 CD.

Open a command prompt and type httpcfg set iplisten -i w.x.y.z:n to set the new IP address (w.x.y.x) you added to your network card and port number on which you want IIS to listen. This inclusion list specifies which IP addresses http.sys listens on and is initially empty by default, which means that IIS listens to all IP addresses.

Then restart IIS because http.sys reads this list only on startup. You don’t have to restart all IIS services, only the HTTP Service.

Summary

It takes a little work, but it’s not difficult as long as you have all the information. I now have PHP, ColdFusion and ASP sites running happily on the same server thanks to this setup and I (and a few clients) couldn’t be happier.