I’m working on getting CommandBox to support multi...
# box-products
r
I’m working on getting CommandBox to support multiple Lucee contexts and I think I’m missing something. In the first instance I’m trying to do this on a Mac using Apache/ModCFML but I also need to do this on Windows with IIS/BonCode. For Apache I have the following enabled in my httpd.conf
Copy code
LoadModule proxy_module lib/httpd/modules/mod_proxy.so
LoadModule proxy_html_module lib/httpd/modules/mod_proxy_html.so
LoadModule proxy_http_module lib/httpd/modules/mod_proxy_http.so
LoadModule proxy_ajp_module lib/httpd/modules/mod_proxy_ajp.so

LoadModule modcfml_module lib/httpd/modules/mod_cfml.so
CFMLHandlers ".cfm .cfc .cfml"
ModCFML_SharedKey "mySharedKey"
For each of the sites I have:
Copy code
<VirtualHost *:80>
	ServerName mySite1

	ProxyPreserveHost On
	ProxyPass / <http://localhost:8500/> nocanon
	ProxyPassReverse / <http://localhost:8500/>

	ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ <ajp://localhost:8009/$1$2>
</VirtualHost>
Where the
ServerName
changes and the
ProxyPass
and
ProxyPassReverse
port numbers increment by 1 each time. For each of the sites I have a similar
server.json
Copy code
{
    "name":"mySite1",
    "web":{
        "host":"mySite1,
        "http":{
            "port":"8500"
        },
        "rewrites":{
            "enable":"true"
        },
        "ajp":{
            "enable":"true",
            "port":"8009"
        }
    },
    "app":{
        "cfengine":"lucee@5.3.4+77"
    },
    "modcfml":{
        "enable":"true",
        "sharedKey":"mySharedKey"
    }
}
Where the values of
name/host
and
port
change in sync with the Apache settings. If I start up CommandBox and start my “base” server on localhost:8500 it come up and I can also access the Lucee admin but I don’t see any of the other contexts in the foot of the Admin Overview page. What am I missing?
b
@richard.herbert if you're using the new ModCFML feature, then you only need a single CommandBox server. That means only one server.json, only one server process, and only one AJP port.
r
Okay, I can understand that but then how do I get the contexts for the other sites?
b
Not sure what you mean when you say "get the contexts".
But you'll be able to see them in the Lucee Server admin page.
r
I’m not seeing them. How do I add them? I guess that’s the understanding I’m missing.
b
You don't
They are just informational
Lucee is just showing you the contexts that exist
They are created automatically as traffic hits the Lucee sever from each webroot
Have you followed this guide to enable modcfml? https://commandbox.ortusbooks.com/embedded-server/modcfml-support
r
Yes, I think I’ve been following that correctly. As you can see I’ve got the
ModCFML
section in my
server.json
So let’s back up a bit. Would you say that my Apache config looks right?
b
No, not if each virtual host is proxying to a different port, lol
That's why I said up front it all needed to be one server
r
They are created automatically as traffic hits the Lucee sever from each webroot
So how do I direct traffic to the one instance of Lucee from each of the webroots is, I guess, the part I’m missing? I’m guessing this line from each vhost is forwarding the request onto AJP on port 8009…
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ <ajp://localhost:8009/$1$2>
…and tis section from the one instance of Lucee that is running on CommandBox should be listerning for that request and creating the context on the fly?
Copy code
"ajp":{
            "enable":"true",
            "port":"8009"
        }
b
The apache and mod_cfml config should look just like it would on a standard tomcat-based lucee install.
CommandBox's modcfml works just the same as the tomcat valve
r
No, not if each virtual host is proxying to a different port, lol
So this should be the same on every vhost?
Copy code
ProxyPass / <http://localhost:8500/> nocanon
	ProxyPassReverse / <http://localhost:8500>
Rather than each be on a different port?
Okay, so changing all the vhosts to…
Copy code
ProxyPass / <http://localhost:8500/> nocanon
	ProxyPassReverse / <http://localhost:8500/>
…now gets all the sites to render the running Lucee instance webroot. How do I get each context to point to their respective webroot? I assume I have to control that in the single
server.json
but I’ve not seen any setting before that controls that kind of setting?
b
I'm guessing mod cfml isn't set up
Use the server logs with --debug to see what's happening
There are log messages each time a new site is hit
If all sites are using the default webroot, then either mod cfml in apache isn't sending the headers or modcfml isn't turned on in CommamdBox to use them.
I don't understand what you're doing with port 8500 though
Are you trying to proxy traffic over 8500 (http) or 8009 (ajp), because it doesn't make sense to have both
r
You’re right the port 8500 thing was a hang over from when I had multiple servers running at the same time, which I’m trying to get away from. So should I be saying this…
Copy code
<VirtualHost *:80>
	ServerName mySite1

	ProxyPreserveHost On
	ProxyPass / <http://localhost:8009/> nocanon
	ProxyPassReverse / <http://localhost:8009/>

	ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ <ajp://localhost:8009/$1$2>
</VirtualHost>
Or remove the
ProxyPass
and
ProxyPassReverse
entries? Regarding the logging, should I be doing
server start --debug --console
to see those headers in flight?
b
That's one way to see the console log. I'm not really an expert on the apache side and haven't messed with it in a long time. I'd refer to the modcfml docs gor the apache connector
I think it may actually create the proxy for you
So it's possible you're doing way too much work there
r
So it’s possible you’re doing way too much work there
I think you might be right but I’m really flapping around trying to work this thing out. My mental model of waht happening is very poor! So setting…
Copy code
ProxyPass / <http://localhost:8009/> nocanon
	ProxyPassReverse / <http://localhost:8009/>
…produced…
Copy code
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request

Reason: Error reading from remote server
…and removing those entries completely render the default Apache webroot…
Copy code
It works!
…so that’s not a good idea 😞 So I don’t know how to address your advice…
Are you trying to proxy traffic over 8500 (http) or 8009 (ajp), because it doesn’t make sense to have both
Okay, I seem to be making some progress! Taking your advice to not do so much work, I’ve change the vhost settings to….
Copy code
<VirtualHost *:80>
	ServerName mySite1

	DocumentRoot /path/to/this/sites/webroot/

	ProxyPreserveHost On

	ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ <ajp://localhost:8009/$1$2>
</VirtualHost>
I seem to be seeing the right webroot contents but there are still some issues but I’m moving forward!
b
Did you check the console output?
I'd also ask your Apache/mod_cfml questions in the #lucee channel because what you really need help with is configuring Apache, not CommandBox it seems 🙂
r
Sorry @bdw429s, I wasn’t ignoring you, I’d just got to the end of a long day (timezones) and I hope you’re asleep right now 🙂 With your advice I think I have a better understanding of how this hangs together so I’m going to start again with a stripped down Apache/CommandBox/Lucee setup and try and log everthing. I’ll report back here when I have something sensible to say.
👍 1
So, a long time later, I've put on hold using Apache and mod_cfml for now and moved onto IIS and BonCode and I've had more success. I'll park this and come back to the Apache/mod_cfml issue later, maybe in the #lucee channel. I have some more, general, CommandBox and context questions but I'll ask fresh questions for those.