Not sure why - but this didn't send from my email :(
Ok… anyone want to know how to achieve this Apache and Lucee?
I played around, did some testing, and this looks pretty solid.
Funny, its almost exactly what I do… just didn’t think about it.
If anyone has any issues with this, let me know, otherwise I’m going to tidy it up, Blog it, and we can add it to the Wiki.
The solution is the same in the server.XML as for Nginx earlier, but I’ll repeat it for completeness sake.
Name which Host Context will be your catchall, by setting defaultHost in the Engine element
<Engine name="Catalina" defaultHost=“catchallHost”>
That means any URLs coming into Tomcat, that do not match a specific Host context, will use “catchallHost”
So lets add the Host element to our server.xml. You could use the default, but I would rather use a fresh one and invalidate the other one, just in case.
<Host name="catchallHost" appBase="webapps">
<Context path="" docBase="/www/" />
</Host>
The docBase is the key here. From Apache you will pass a RELATIVE path based on this.
You could just map it to /www or /home/websites or c:\webs or whatever is relevant for you.
Just remember, it has to be a PARENT folder of all of your sites… you could add alias context paths for a complicated set of directories, but lets keep it simple.
Now, in my blog posts, I change my ports
So AJP is 8024
HTTP is 8504
Shutown is 8004
Now, in apache, I would usually have this code, based on the AJP protocol.
<Proxy *>
Allow from 127.0.0.1
</Proxy>
ProxyPreserveHost On
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:8024/$1$2
What this does, it match everything with cfc or cfm or cfml, and then proxy to ajp localhost 8024… and tack on the matches.
If I do this now, it will match the /www from my context above.
I would normally add a Host context with a matching name, like the following
<Host name="
meetthefamily.local.com" appBase="webapps">
<Context path="" docBase="/www/ITB2014-Meet-The-Family"></Context>
</Host>
And that would pick up that Host and display it correctly.
This is our issue.
But by removing that Host Context, we can use the main context, and just adjust the ProxyPass
We change it to look like this… where we pass the Relative Directory from the main Host Context or /www
<Proxy *>
Allow from 127.0.0.1
</Proxy>
ProxyPreserveHost On
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:8024/ITB2014-Meet-The-Family/$1$2
So now it works, and it works great.
The full request flow.
So apache sees a domain like
meetthefamily.local.com, matches the Servername and pulls up the Apache Virtual Host… like this.
All non cfml resources are served from Apaches DocumentRoot
<VirtualHost *:80>
ServerAdmin
gpi...@mydomain.com DocumentRoot "/www//ITB2014-Meet-The-Family/"
ServerName
meetthefamily.local.com<Proxy *>
Allow from 127.0.0.1
</Proxy>
ProxyPreserveHost On
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:8024//ITB2014-Meet-The-Family//$1$2
</VirtualHost>
The ProxyPassMatch looks for all CFML requests and then passes it to Tomcat’s default Host, and looks inside the WWW folder (root) for the relative path, in this case ITB2014-Meet-The-Family
Of course, if you want a separate Host Context for given apps etc, you surely can.
Since you are still using the AJP etc, you could setup a cluster of instances, and pass the path down too.
I am going to have to experiment with that more.
Simple, and no more stopping and starting Tomcat anymore.
BEAUTIFUL :)
I am glad I subscribed to get every post to this group… otherwise I might have missed this.
Very cool.
Gavin Pickin
http://www.gpickin.com