Skip to main content
Participant
October 30, 2009
Question

Apache/ColdFusion 9 per-directory application isolation

  • October 30, 2009
  • 1 reply
  • 2064 views

With CF9 enterprise, I'd like to connect to multiple CF instances in a single Apache virtual host.

For example,

mydomain.com/app1 -> handled by instance1
mydomain.com/app2 -> handled by instance2

It seems most people accomplish this by using separate vhosts, but I was wondering if this could be done at a directory level.  I've tried using <Directory> and <Location> stanzas with their own JRunConfig directives, but they end up overwriting the JRun config for the entire virtual host.

If anyone knows of a built-in way to accomplish this, I would be interested.  Alternatively, I'd like input on using an Apache reverse proxy configuration so that I can map /app1 to the WebService port of the JRUN instance:

mydomain.com/app1 -> localhost:8301/app1
mydomain.com/app2 -> localhost:8302/app2

Has anyone had luck with this?  Does anyone see issues with this or have a better idea?

Thanks!
Seth S.

    This topic has been closed for replies.

    1 reply

    Known Participant
    November 30, 2009

    hi, i have the same problem, link here:

    http://forums.adobe.com/thread/469905?tstart=0

    the only "solution" i find at the moment is using mod_proxy to manage all the incoming request and proxy them to the right VirtualHost (always one for each instance), but i don't like very much this workaround

    Participant
    November 30, 2009

    @clagio - I went down the same road you did with the Location directive.  Apparently mod_jrun does not respect the Location or Directory container contexts.  I experienced the same behavior that you described - the last defined set of JRunConfig statements took precedence for the entire vhost regardless of URL path.

    After talking with some community experts I came up with several possible solutions:

    1) Use Tomcat as your JEE server and deploy ColdFusion as an ear file.  Tomcat/Apache connectivity is setup with a sub-module of mod_proxy called mod_proxy_ajp.  This module works with rewrite rules to create virtual paths that can be mapped (proxied) to different Tomcat/CF instances.  (There is no "mod_proxy_jrun" so we can't do the same thing with JRun)

    2) The solution I first recommended:  Use mod_proxy (specifically mod_proxy_http) and the internal Java web server built in to JRun.  In this case you are just doing a reverse proxy from Apache port 80 to JRUN port 8301 (or whatever).  URL requests to http://mydomain.dom/path1 get mapped to http://localhost:8301/path1.  The end result is transparent to the user.  This approach isn't ideal, because it requires Apache to proxy the full HTTP request rather than communicate using a binary protocol like with mod_jrun or AJP.  Also, the Java web server may not be robust enough for all production environments.

    3) And the solution that I liked the best for my situation was to create separate Apache vhost configs for each CF instance.  These vhosts would be "internal" and not accessible to front-end users.  In my main public-facing vhost I then would use normal mod_proxy rewriting rule to rewrite my URL paths to the other Apache vhost - that vhost would then use mod_jrun to communicate with JRun using the more efficient binary protocol.  Here's more detail on that setup:

    This is a simplified config that is currently working using an internal Apache vhost to connect to the JRun ProxyService.  The default handler for CF is defined in the main configuration:


    <IfModule mod_jrun22.c>
        JRunConfig Verbose false
        JRunConfig Apialloc false
        JRunConfig Ignoresuffixmap false
        JRunConfig Serverstore /opt/jrun4/lib/wsconfig/myinstance1/jrunserver.store
        JRunConfig Bootstrap 127.0.0.1:51002
        AddHandler jrun-handler .jsp .jws .cfm .cfml .cfc .cfr .cfswf
    </IfModule>


    So by default CF requests are sent to myinstance1, port 51002. However, using rewriting any requests sent to /webstore/*.cfc,*.cfm are
    redirected to webstore.localdomain which is configured to proxy to myinstance2, port 51020.

    <VirtualHost *:80>
            # This VHOST functions as a container to map requests from mydomain.dom/webstore to
            # a dedicated JRun instance.

            DocumentRoot "/var/www/vhosts/www.mydomain.dom/html"
            ServerName webstore.localdomain

            # Deny all non-local requests, this should by requested via proxy from the main
            # public-facing VHOST
            <Location />
                    Order deny,allow
                    Deny from all
                    Allow from 127.0.0.0/255.0.0.0 ::1/128
            </Location>

            # JRun Settings
            <IfModule mod_jrun22.c>
                    JRunConfig Verbose false
                    JRunConfig Apialloc false
                    JRunConfig Serverstore /opt/jrun4/lib/wsconfig/myinstance2/jrunserver.store
                    JRunConfig Bootstrap 127.0.0.1:51020
            </IfModule>
    </VirtualHost>
    <VirtualHost *:80>
            DocumentRoot "/var/www/vhosts/www.mydomain.dom/html"
            ServerName www.mydomain.dom

            RewriteEngine on


            # Proxy webstore requests to internal VHOST dedicated to specific CF/JRun instance
            RewriteRule  ^\/webstore\/(.+)\.cfm(.+)? http://webstore.localdomain/webstore/$1.cfm$2 [P,L]
            RewriteRule  ^\/webstore\/(.+)\.cfc(.+)? http://webstore.localdomain/webstore/$1.cfc$2 [P,L]
    </VirtualHost>


    Note: I added webstore.localdomain to my /etc/hosts file.

    Known Participant
    December 1, 2009

    thanks sstone for your feedback, all of your solutions, are good "workaround",and i agree with you saying that the last one is the best one..

    but it's possible that there isn't any official documents from Adobe that suggest one solution over the others?

    regarding the "Apparently mod_jrun does not respect the Location or Directory container contexts.", i made some test with these configuration:

    test1:

        <IfModule mod_jrun22.c>
          JRunConfig Verbose false
          JRunConfig Ssl false
          JRunConfig Ignoresuffixmap false
          JRunConfig Serverstore /opt/cf/jrun4/lib/wsconfig/2/jrunserver.store
          JRunConfig Bootstrap 127.0.0.1:51002
          JRunConfig Apialloc false
        </IfModule>
        <Location /test1>
          AddHandler jrun-handler .cfm .cfml .cfc .jws .cfr .cfswf
        </Location>
        <Location /test2>

         #empty just to explain - you can delete /test2 location
        </Location>

    Test2:

        <Location /test1>
          <IfModule mod_jrun22.c>
            JRunConfig Verbose false
            JRunConfig Ssl false
            JRunConfig Ignoresuffixmap false
            JRunConfig Serverstore /opt/cf/jrun4/lib/wsconfig/2/jrunserver.store
            JRunConfig Bootstrap 127.0.0.1:51002
            JRunConfig Apialloc false
            AddHandler jrun-handler .cfm .cfml .cfc .jws .cfr .cfswf
          </IfModule>
        </Location>
        <Location /test2>

         #empty just to explain - you can delete /test2 location
        </Location>

    In both test the code in /test1 is parsed from cf, and the code in /test2 location it's printed but not parsed, so mod_jrun respect the Location directive, but seems that these values are "global" for all the Virtualhost, and a new "call" of the same parameter overwrite the first one..

    I tried working with "SetHandler jrun-handler" (like i do with weblogic) directive without success.. but i think that the solution, if there is one, is working with handlers..