Results 1 to 7 of 7

Thread: Hosting multiple domains / websites with dm Server

  1. #1
    Join Date
    Jun 2008
    Posts
    25

    Default Hosting multiple domains / websites with dm Server

    I'm currently evaluating dm Server as a potential replacement server for our half-dozen websites currently running on Tomcat. However our scenario appears to not be handled well - or at all - by dm Server... so I'd like to know my evaluation is correct, and whether there are any plans to handle it.

    In short, our scenario is that we host a few websites on a single server. The websites are different WARs but share common code in a common JAR. Each website has a different domain name, but they all run in the same instance of Tomcat.

    dm Server should be ideal because it allows the common code to be put in an OSGi module shared by the multiple websites. But dm Server seems to lack Tomcat's ability to handle multiple websites / host names. dm Server allows a web module to be deployed to a particular context path, but not to a particular host. So we cannot have all our websites running in the one instance of dm Server.

    In Tomcat, we configure server.xml like this to handle multiple hosts:

    Code:
    <Engine name="Catalina" defaultHost="www.example.com">
    	<Host name="www.example.com">
    		<Context docBase="/path/example.com" path=""></Context>
    		...
    	</Host>
    	<Host name="www.anothersite-example.com">
    		<Context docBase="/path/anothersite-example.com" path=""></Context>
    		...
    	</Host>
    	...
    </Engine>
    Is there any way of achieving a similar configuration with dm Server? As far as I can tell, the answer is no.

    If the answer is no, then my question is: are there any plans to support multiple hosts in the future?


    A workaround
    There is a workaround that we are contemplating. I'm listing it here just in case readers of this message find it useful -- and if you have suggestions for improving the workaround, please chime in.

    The workaround is to use Apache HTTPD to handle the multiple host names. The configuration is:
    • Apache HTTPD 2.2 handles all incoming HTTP/HTTPS requests
    • mod_rewrite converts host names into context paths for example www.example.com -> localhost/ExampleWeb and www.anothersite-example.com -> localhost/AnotherSiteExampleWeb
    • mod_jk passes the requests to dm Server via AJP
    • dm Server treats the multiple websites as being a single website, but with multiple context paths

    There is one big limitation of this approach: Java assumes that the context path (such as /ExampleWeb) is part of the URL -- but in fact it's not. So java.net.URL and <c:url> etc will return invalid URLs like /ExampleWeb/path/index when what we wanted is /path/index

  2. #2
    Join Date
    Jul 2005
    Location
    Hamburg, Germany
    Posts
    34

    Default

    I think you could use mod_proxy in the apache httpd.
    A proxy and reverse proxy should to the trick.

  3. #3
    Join Date
    Jun 2008
    Posts
    25

    Default

    Quote Originally Posted by KnisterPeter View Post
    I think you could use mod_proxy in the apache httpd.
    You're probably right, mod_proxy should work as well. But I've ended up using mod_rewrite and mod_jk, because it allows HTTPD to serve up static content such as images without invoking dm Server.

    So now my HTTPD configuration in conf/extra/httpd-vhosts.conf looks like:
    Code:
    <VirtualHost *:80>
        DocumentRoot "/path/static/example.com"
        ServerName www.example.com
        RewriteEngine on
        RewriteRule ^/images/			-	[NC,L]
        RewriteRule ^/(.*)	/ExampleWeb/$1	[NC,PT]    
        JkMount /* dmServerJK
        JkUnMount /images/* dmServerJK
    </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot "/path/static/anothersite-example.com"
        ServerName www.anothersite-example.com
        RewriteEngine on
        RewriteRule ^/images/			-	[NC,L]
        RewriteRule ^/(.*)	/AnotherSiteExampleWeb/$1	[NC,PT]    
        JkMount /* dmServerJK
        JkUnMount /images/* dmServerJK
    </VirtualHost>
    and conf/jk/workers.properties looks like:
    Code:
    worker.list=dmServerJK
    worker.dmServerJK.type=ajp13
    worker.dmServerJK.host=localhost
    worker.dmServerJK.port=9010
    From a technical perspective this works. But we still have the problem that the URLs used by Java / dm Server are different to the actual URLs that users see in their browser. This means our application has to be modified to catch URLs generated by Java and remove the context path from them -- not an ideal solution.

    Ideally dm Server would allow multiple hostnames to be used by one server, just like the underlying Apache Tomcat instance does. That would simply things greatly.

  4. #4
    Join Date
    Jun 2008
    Posts
    25

    Default

    I'd like to formally request that support for multiple hostnames is added to dm Server. Is this something that I should do by raising an issue in Jira at https://issuetracker.springsource.com/browse/PLATFORM ?

  5. #5
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Yes, that would be the place

  6. #6
    Join Date
    Jul 2005
    Location
    Hamburg, Germany
    Posts
    34

    Default

    Quote Originally Posted by gutch View Post
    From a technical perspective this works. But we still have the problem that the URLs used by Java / dm Server are different to the actual URLs that users see in their browser. This means our application has to be modified to catch URLs generated by Java and remove the context path from them -- not an ideal solution.

    Ideally dm Server would allow multiple hostnames to be used by one server, just like the underlying Apache Tomcat instance does. That would simply things greatly.
    For sure it would be easier if multiple hostnames could be used, but with mod_proxy you should be able to remove the context path from your urls and you could also serve static content from your httpd server. It's just a matter of configuration.
    You only need a uri pattern where you could decide which request is static content and which should be proxied to tomcat.

  7. #7
    Join Date
    Jun 2008
    Posts
    25

    Default

    Thanks KnisterPeter, I now realise that mod_proxy probably can provide a full workaround. I had thought that it couldn't, but the new ProxyPassReverseCookiePath directive added in httpd 2.2 seems to solve that.

    I haven't tried it yet, but I expect that a properly configured mod_proxy and mod_proxy_html would modify the incoming request URL and cookies, and then modify the outgoing response URL, HTML and cookies.

    However I'm a little uncomfortable about the extra complexity and maintenance required for putting that solution into production, as well as the likely extra processor load to parse and transform all the HTML. Thus I have raised a feature request for dm Server to support multiple hostnames at
    https://issuetracker.springsource.co...e/PLATFORM-241 - we're much more likely to start using dm Server if it does support multiple hostnames.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •