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.
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.
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.
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.
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>
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>
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.
21 Responses for "ColdFusion on JBoss with Apache Proxy"
Thanks a ton for this. I haven’t been able to find any other resource that details how to hook Apache to JBoss like this.
Hi Steve.. Need help!!! I am trying to set up JBoss as my web server. Just downloaded JBoss 4.2.1GA. Changed the port number to 80 in server.xml. I have uploaded my web page in the ROOT.war file. It works fine as when I enter http://localhost. In server.xml I have also put http://www.XYZ.com under the tags… My DNS is set up correctly. Where is jboss-web.xml? in the latest version of JBoss. What else do I need to do to get JBoss wrking as a ser server?
Thanks in advance…
Rom, you need to create the jboss-web.xml file in the WEB-INF directory of your application.
Anybody knows how to configure JBoss with IIS 7 or 6?
So Steve, my copy of Apache 2.2.6 says that ProxyPass is not a valid command inside the virtualhost section. Apache won’t start, and that’s the error that it leaves in my windows event log. Apache’s documentation suggest that ProxyPass isn’t one of the accepted params. Any ideas? Thanks.
ah, digging deeper, I see that it’s definitely a supported param, but I’m still getting the error.
Sorry to flood your site with my stuff.
I have it working now; just needed to uncomment the LoadModule lines for mod_proxy, mod_proxy_ajp and mod_proxy_http.
i follow the steps u provide.
but im getting this forbidden message “You don’t have permission to access / on this server.”
Hi,
Cheers for this useful guide. I have now got our setup working in beautiful harmony. There is one thing that needs mentioning to get it working properly.
The Apache Proxy line should use the DNS name of the JBoss virtual host, rather than an IP address like 127.0.0.1. Otherwise JBoss won’t know what domain is being requested (Proxy doesn’t forward that info). So in other words, you need to have:
ServerName http://www.orbwave.com
ProxyPass / http://www.orbwave.com:8080/
That sort of thing. Took me a while to work out.
Many thanks!
Thanx William. Seems to be working after that. But seems like it wont work if i have 2 jboss instance. I had to put both in the same server and deployment folder.
What do i need to do if both my application is using SSL? I tried putting https:// at ProxyPass but didn’t seem to work. the message is “proxy: No protocol handler was valid for the URL.If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.”
Did i configure it wrong or do i need to get SSL for apache too?
@William:
Very good point, and I’ll make sure that I add it to the documentation. There are multiple ways that a server can be setup and I only covered one of them.
In my case, I had Apache running on my web server box and JBoss running on my application box, so I had to use an internal IP address, but if you have both sitting on the public web server, then your settings would be applicable.
One correction is that ProxyPass does pass the domain name, since I’m using it in my setup and the requests are being handled properly for the multiple domains.
try using this for http to https, works for me
my jboss is using ssl.
ServerName xyz.com
RewriteEngine On
RewriteRule ^(.*)$ https://xyz.com:$1
ServerName abc.com
RewriteEngine On
RewriteRule ^(.*)$ https://abc.com:$1
i am creating virtual hosts for my application i have one doubt [whether it is possible to create virtual host with out having a proxy of Apache]… pls guide me
Thanks in advance
Hi,
Great guide!
We are trying to move from Apache/CF7/JRun to Apache/CF8/JBoss. With jrun, we had a connector module for Apache (mod_jrun20.so, much like Mod_jk to connect Apache to tomcat). All the web content lives in the Apache doc tree. An instance of Apache lives at cfpro. and its htdocs holds a directory for each CF app. In both Tomcat and JRun environments, we have Apache handle SSL.
If we use ProxyPass, will Apache still hold the cfm content as a doc tree, or does that all move to the cfusion8 server under JBoss? Does there need to be a connector for apache other than the mod_proxy, mod_proxy_ajp and mod_proxy_http? How are those modules configured (used to be wsconfigx directories when running CF under JRun?
Thanks in advance.
Paul
Before I start – excellent site!
I’m trying to migrate my site from Apache/JRun/CF/Windows to Apache/JBoss/CF/Linux using this guide/site as a source of information. The only issue I’m having at the moment is detecting HTTPS using the CGI scope variable in CF8. I can browse to ports 8080 and 8443 and check the Tomcat Status (all ok). How do I go about setting up Apache 2.2.3 to connect using mod_proxy over SSL? I’m using JBoss 4.2.3
I’ve made some progress. I can browse to http://:8080, https://:8443 and I’ve setup apache to proxy to JBoss on port 8080 and 8443 verifying the connection using Tomcat status – http://IP and https:// works fine. As soon as I deploy CF8 WAR file I hit problems – https:// returns ‘Bad Gateway The proxy server received an invalid response from an upstream server’ but http:// works fine???? IF I remove cf8 war, everything seems to work fine again. Any idea what would cause https to fail?
Dear Stave,
Mentioned stuff very useful am very thankful to you.
Am not able see parsed jsp with the above configuration.
Am getting the code instead of html content.
Kindly help me in this matter am stuck in server migration work.
OS : CentOS5
WS : Apache2.2.11
AS : Jboss4.2.x
Thanks and Regards,
Syed
I think I have the solution people are looking for, I’ve got my *.cfm files in my /htdocs folder and I’ve got the coldfusion.ear installed on jboss 5.0.
First I installed apache as normal, then jboss as normal.
Next renamed the ROOT.war in jboss and installed CF8 as ear file per the adobe live docs with a context-root of /
Next I installed and configured mod_jk.so normally, standard worker file etc. for ease I named my worker localhost so I didn’t need to edit it in jboss.
Now the trick, in my mod_jk.conf file I added
JkMount /*.cfm localhost
JkMount /*.cfc localhost
JkMount /*.cfml localhost
This passes my Coldfusion templates into jboss/cf8 but you’ll get 404 errors from coldfusion because it’s referencing / based on it’s content root. Easy fix in linux :)
In my $JBOSS_HOME/server/default/deploy/cfusion.ear/cfusion.war/ directory I simply used ln -s /htdocs/Application.cfm Application.cfm etc for my root templates and then ln -s /htdocs/mail mail etc for all my folders that contained CFM templates.
That’s it, now my implementation is still what the dev team is used to, all templates and pages in /htdocs and apache still serves out everything not coldfusion html, php, cgi, etc
Ripped my hair out figuring it out and searching the web, but all said and done a lot simpler then I thought it was.
I have an EAR file I am trying to deploy alongside various WAR deployments on JBoss 4.2.3
The individual standalone WAR deployments are all working fine and are just a copy of the same application that is contained inside the EAR but the EAR deployment and it’s included WAR(s) does not work correctly.
I am receiving a blank white page in the browser when I visit the virtual host that the jboss-web.xml is configured to associate with this EAR. The other virtual hosts associated with the standalone WAR deployments all work fine and are configured the same way.
I get no errors on startup and JBoss reports that the site was started. I have a jboss-web.xml file in the WAR’s WEB-INF that ties it into a virtual host definition from server.xml. This works on every other type of configuration except the EAR. I keep getting just a white page, as if JBoss can’t connect the WAR in the EAR to the host or maybe the WAR isn’t starting right or I have some config wrong here. I have tried this with mod_jk, ProxyPass and AJP forwarding / rewrite, all to no avail.
When I fire up JBoss it creates the flex and railo directories in webwar1.war/WEB-INF as well as a railo-server directory as railo.ear/lib/railo-server but still just serves me a blank white page.
Here is where I stand…
I have a set of shared Railo JAR files are located in /JBoss/server/default/deploy/jboss-web.deployer/railojars/lib (I have told jboss-service.xml to include this as a classpath, and removing these JAR files does not fix my problem)
My site1.WAR and site2.WAR files are in the deploy folder and each contain an index.cfm and a WEB-INF with web.xml and jboss-web.xml mapped to a virtual host. They each use this shared Railo JAR instance and run perfectly. The sites I’ve configured in server.xml with a docPath and appPath to an outside folder use this shared JAR installation and run perfectly. Everything is good with this.
If I place a railo1.war, railo2.war, etc in the /JBoss/server/default/deploy folder (the full WAR with Railo lib folder) those sites use the Railo instance contained within the WAR. This is also great.
So, my only problem left is this:
under /JBoss/server/default/deploy I have created railo.ear
Inside railo.ear is: META-INF which contains application.xml with:
Railo3
Railo3
webwar1.war
/webwar1
It also contains webwar1.war which contains: index.cfm and WEB-INF
WEB-INF has has web.xml, lib and jboss-web.xml
jboss-web.xml looks like this:
/
foo3.com
From server.xml:
http://www.foo3.com
foo3.com is using jk_mod (I’ve tried ProxyPass and AJP with rewrite too) to send to JBoss via a virtual host from Apache. The other two sites (foo1.com, foo2.com) which are mapped to WAR deployments are configured the exact same way and work fine.
The WEB-INF includes the lib folder so I would expect this webwar1.WAR instance to use the Railo JAR files contained in that lib folder. The problem is that when I start JBoss, all of my other sites configured their various ways work, but the site in webwar1.war is not coming up. I simply see a white page in the browser.
So, either the jboss-web.xml in WEB-INF in the webwar1.war file is not being connected to the defined in server.xml or something else is going wrong here. My other standalone WAR installations and the shared JARs sites all see their respective descriptors as marked in their jboss-web.xml and have the same content as this deployment.
So, I’m just trying to figure out what I need to do to get this last EAR configuration to work.
The way I am trying now seems like each WAR would try to use the JAR files it contains, but I want to have one set of shared JAR files for the whole EAR and then each WAR file in the ear use those JARS.
I want to be able to have webwar1.war, webwar2.war, etc under this one EAR configuration so I have moved the lib folder out of webwar1.war/WEB-INF/lib and into railo.ear/lib
I would love to set it up this way, but I can’t even get one WAR with its own JAR files to load up right when inside the EAR. I have tried this new configuration and get the same blank white page in the browser.
Any ideas?
JBoss gives me no errors. Another odd thing is that I don’t get an error from Apache like I do when I try to visit a site that is improperly configured and did not start up. And if I visit a site that is not set up as a host in JBoss and I am redirected via jk_mod to JBoss, I see the JBoss default page. I am not seeing this default page when I visit the virtual host associated with this webwar1.war in the railo.ear, so JBoss must know that it’s supposed to do something with the domain / virtual host or else it would show me that default JBoss page. Instead I see a blank white one.
I should also mention that this works on JBoss 5.1. The railo.ear configured the exact same way latches onto the virtual host and works properly.
Help? Thanks!!!!
Oops, my code didn’t show up, view the source for that, sorry!
? ????? ???-?? ????????, ?? ? ??? ???? ????? ??????? ????????
Leave a reply