Search code examples
jakarta-eeglassfishglassfish-3application-server

GF 3.0.1 + Virtual Server: www.myhost.com:8080/projectname-war => www.myhost.com. How?


EDIT

I need to change www.myhost.com:8080/myproject-war to www.myhost.com. Here is what I've been trying:

I configurate the Virtual Server: server. I have still have default Network Listeners to be http-listener-1 and http-listner-2. I change the Default Web Module to ScholarActive#ScholarActive-war.war (The only option in the drop down list, since I only deploy 1 application).

For the docroot, I try this

${com.sun.aas.instanceRoot}/applications/ScholarActive/ScholarActive-war_war

or this

${com.sun.aas.instanceRoot}/applications/ScholarActive/

Both does not work. What does docroot need to point to, for this to work?

what I try to do is: when I type localhost:8080/ScholarActive-war, then my application load, I want to make so that if I type locahost:8080, it will load the app as well, then what left is changed the port to 80. But no luck. Any Idea?


Solution

  • If you are ok about running glassfish as root, simply edit the domain.xml file, changing port 8080 to port 80.

    If you do not want to run glassfish as root (as you shouldn't), then you can front glassfish with apache. I blogged about running both glassfish v2 and v3 behind apahce httpd.

    Alternatively, you can use iptables to route all traffic from port 80 to port 8080 like so:

    iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 8080 
    

    As for the 2nd part of the question - removing the context root, it's just a matter of deploying your application with a "/" context root. There are again a few ways to achieve this. You can set the context root for your webapp using the Admin web console, during, or after it's deployed. You can set it via the command line:

    asadmin deploy --contextroot "/" webapp.war
    

    Or you can set the context-root of your sun-web.xml file to /.

    Alternatively, you could set the default web module for a virtual server, similarly to how the web admin console is the default web module for port 4848. I've never tried this though.


    Answering the edited question: To change the default web module, from the glassfish admin console (localhost:4848), goto:

    Configuration -> Virtual Servers -> server

    There you will see a drop-down list for the "Default Web Module". Select your deployed web application. This application will now respond on the root url. I noticed after trying this myself, that I was re-routed to the context root after logging in. This could possibly be fixed by setting the context roop of my webapp to ""/", or by using the


    Yet another possibility, is to use mod_proxy in apache httpd, and map "/" of port 80 to "/myWebApp" on port 8080. This avoids the above mess altogether.