Skip to main content

Another thread on virtual servers

16 replies [Last post]
malakh
Offline
Joined: 2008-02-15

I'm not sure if this is the right forum for this (it could be a network question), but here's the scenario:

We have a registered domain name, and have changed their MX record to point the domain to our web server. The glassfish V2 server is currently hosting the web site just fine and everything is good.

What we want to do is redirect another domain to this server and have it host that site as well. The problem is that I can't figure out how to tell Glassfish how to interpret someone trying to reach www.abc.com from www.def.com and to throw them to the appropriate webapp.

I have tried reading this:

http://docs.sun.com/app/docs/doc/819-3671/ablsw?a=view

and it helped a little, but it seems incomplete. Any straight-forward guides out there to making www.abc.com point to 172.1.1.1/WebAppA and www.def.com point to 172.1.1.1/WebAppB?

I'll apologize in advance if this is posted elsewhere, just please point me to it, as I couldn't find it myself.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Dick Davies

On Thu, Jul 31, 2008 at 11:03 PM, wrote:
> OK, they are both now pointing to http-listener-1, which is listening to port 80. I have set their respective default web modules.
>
> One problem - The http-listener-1 is requiring a default virtual server, and won't let me set it to blank.

That's not really a problem - you need something that will respond to
ancient browsers that don't send a
host header. Pick one, or create one with just an index page pointing
to your other sites.

--
Rasputnik :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

malakh
Offline
Joined: 2008-02-15

Here's a strange little side effect -

Everything is working correctly (http-listener-1 is pointed to www.abc.com, and http-listener-2 (with ssl) is pointed at www.def.com).

However, if I go to http://www.def.com, it will load the abc.com webapp, and if I go to https://www.abc.com, it will load the def.com webapp.

I'm pretty sure this has to do with the default Web Module setting, but how do I get around it? And by the way, my hosts line just has "www.abc.com,abc.com" and similar for the def.com

jluehe
Offline
Joined: 2004-12-01

See this thread:

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

Let me know if this answers your question.

malakh
Offline
Joined: 2008-02-15

If a blank default-virtual-server would do the trick and return a 404, then yes, that would solve my problem.

I also tried using a "redirector" virtual server that had a webapp that only contained a single JSP that checked the request.getRequestURI() and if it contained "abc" it redirected to http://www.abc.com, and if it contained "def" it would redirect to https://www.def.com.

I couldn't get it to work, though. I changed all default web apps to the redirector, but all it would serve was a blank page for everything. I don't understand why though, since the webapps were correctly paired up with their virtual servers in the Web Applications section.

malakh
Offline
Joined: 2008-02-15

OK, they are both now pointing to http-listener-1, which is listening to port 80. I have set their respective default web modules.

One problem - The http-listener-1 is requiring a default virtual server, and won't let me set it to blank.

bilgehan
Offline
Joined: 2007-10-06

You can set any of the virtual servers as default. If a matching host name is not found (e.g. user enters ip address instead of domain name), request will be directed to that server. You can also define another server for serving these requests.

Message was edited by: bilgehan

malakh
Offline
Joined: 2008-02-15

Everything appears to be working! Hooray!

Thank you all for your help. I could not have done it without you.

malakh
Offline
Joined: 2008-02-15

OK, so I have created a new http-listener on port 8585, and it is set to the new virtual server.

When someone enters the www.abc.com url, how do I tell glassfish to load the 8585 port, instead of the 80 port which is set on the other website?

bilgehan
Offline
Joined: 2007-10-06

You can't send someone to another port. By entering www.abc.com the user says he wants port 80. You must do the following:

If you have only one IP address, you will use one http listener and two virtual servers. Virtual servers will be identified by their host-names. One virtual server will accept requests for host www.abc.com and the other server www.def.com. Default web module for server www.abc.com must be webapp1 and www.def.com must be webapp2.

km
Offline
Joined: 2005-10-28

> If you have only one IP address, you will use one
> http listener and two virtual servers. Virtual
> servers will be identified by their host-names.

Which translates to "hosts" attribute on virtual-server element in domain.xml.
It's not required that this is one. There can be multiple "host names" (in the host header)
that a particular Virtual Server (whose configuration is again specified as "virtual-server"
element) can server content for.

Regards,
Kedar

malakh
Offline
Joined: 2008-02-15

New question

malakh
Offline
Joined: 2008-02-15

OK, everything is working now as expected. For those who are interested, here is how to set up multiple virtual servers on one http-listener (or in my case, one http and one https listener) and not have the problem of http://www.def.com loading the abc app and https://www.abc.com loading the def app:

1) Add a virtual server for each webapp.
2) In each virtual server setting, set the Default Web Module to the applicable webapp
3) Create ANOTHER webapp (I called mine Redirector) that contains only a single JSP or servlet that checks the request.getRequestURL() value for your domain, and uses response.sendRedirect() to direct it to the correct website.
4) Create another virtual server for the Redirector webapp
5) Set the Default Virtual Server on the http listener to use the Redirector virtual server
6) Double check your virtual servers to make sure they are all using the correct http listeners
5) When you deploy your web app, make sure you set the correct virtual server to associate it with in Applications -> Web Applications
6) Restart Glassfish with stop-domain/start-domain.

Voila!

jluehe
Offline
Joined: 2004-12-01

Thanks for posting this workaround! I'm sure it will help others.

Wolfram Rittmeyer

This is definitely the correct forum.

Jan Luehe posted about virtual servers on his Blog:
http://blogs.sun.com/jluehe/entry/virtual_hosting_features_in_glassfish

His approach uses also different http-listener for each virtual server.

Shameless plug: I have also blogged about how to achieve this using the
asadmin command - though I use the same listener for all virtual servers:
http://weblogs.java.net/blog/writtmeyer/archive/2008/02/virtual_servers....

--
Wolfram Rittmeyer

glassfish@javadesktop.org wrote:
> I'm not sure if this is the right forum for this (it could be a network question), but here's the scenario:
>
> We have a registered domain name, and have changed their MX record to point the domain to our web server. The glassfish V2 server is currently hosting the web site just fine and everything is good.
>
> What we want to do is redirect another domain to this server and have it host that site as well. The problem is that I can't figure out how to tell Glassfish how to interpret someone trying to reach www.abc.com from www.def.com and to throw them to the appropriate webapp.
>
> I have tried reading this:
>
> http://docs.sun.com/app/docs/doc/819-3671/ablsw?a=view
>
> and it helped a little, but it seems incomplete. Any straight-forward guides out there to making www.abc.com point to 172.1.1.1/WebAppA and www.def.com point to 172.1.1.1/WebAppB?
>
>
> I'll apologize in advance if this is posted elsewhere, just please point me to it, as I couldn't find it myself.
> [Message sent by forum member 'malakh' (malakh)]
>
> http://forums.java.net/jive/thread.jspa?messageID=290766
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

malakh
Offline
Joined: 2008-02-15

Is there any advantage/disadvantage to using a separate listener for each virtual server?

bilgehan
Offline
Joined: 2007-10-06

With different listeners, you can listen on different ip addresses or ports. Also a note on listeners. With default installation, it isn't possible to have more than one http listener with same port although the IP addresses are different. This is a bug and mentioned at glassfish issues 570, 3095 and 5067. Adding -Dcom.sun.enterprise.server.ss.ASQuickStartup=false seems to fix the problem.