users@glassfish.java.net

Re: Multiple websites on Glassfish

From: <glassfish_at_javadesktop.org>
Date: Wed, 25 Aug 2010 11:22:30 PDT

> The "best" way in my opinion is to use Apache as a
> proxy to your Glassfish instance(s). You then create
> and configure Apache virtual hosts that proxy to the
> required GF listener ports.

One mans "best" is another mans bitter pill. The less Apache HTTPD in my life, the better, frankly.

> This solution is very flexible and does not require
> GF to listen to port 80 (which has other
> implications).

Only implication here is that Glassfish is running from root. On Solaris, this is certainly not a problem (SMF). On Mac OS it's not a problem (launchd). I dunno what shenanigans you need to do this on Linux or Windows.

Anyhow, GF (2.1) goes this just fine.

First, you need a host name, and you need to makes sure the host resolves properly (i.e. ping hostname works), otherwise GF will complain.

Next, in the Console, go to Configuration -> HTTP Service -> HTTP Listeners and edit one of the http-listeners (like http-listner-1) to use port 80, or simply create a new http-listener.

Next, go to Configuration -> HTTP Service -> Virtual Servers and create a new Virtual Server. Here you simply need to specify the http-listener you are using, and the hosts you wish that virtual server to support. The detail here is that the list of hosts is comma separated, and can have NO SPACES. (Perhaps they fixed this, but it was a problem before.) Those hosts MUST resolve, or GF will complain. I do not recall is GF supports wildcards (like *.example.com), I don't believe it does. I haven't had to use it.

Finally, when you deploy your WAR/EAR, you can tell it (on the deploy page) which virtual server to use.

This works great for me.

I have not used the Default Web Module on the Virtual Server, so I can't speak to that, but I have used the docroot field for a simple static site, I link the WAR/EARs on deploy.

Works a peach.
[Message sent by forum member 'whartung']

http://forums.java.net/jive/thread.jspa?messageID=481000