Question

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?

Was it helpful?

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.

OTHER TIPS

In your web container,you should set /myproject-war as the root path, then change the listening port from 8080 to 80. Restart the web container,you can browser you web through http://localhost/,if you want to use http://www.myhost.com instead, add a line like www.myhost.com 127.0.0.1 at the end of you hosts file.This just works for local web site.

Most often I front tomcat/jboss/jetty with apache and mod_proxy or mod_jk. This way, apache listens on port 80/443, and speaks to the j2ee server on port 8080/8443 (or 8009 for mod_jk).

I think that the Glassfish web container is based on tomcat with tomcat you can call your web app file ROOT.WAR which does what you want. Try calling your web app ROOT.war and see if that does what you want, and let us know.


There is no way to configure what you want from within web.xml since it only contains vendor neutral setting. The settings you need to change are application server specific. If you edit your post and let us know which application server you are using we can point you in the right direction on how to do what you want.

This page provide me the solution.

http://blogs.oracle.com/alexismp/entry/glassfish_tip_have_your_application

However, my security authentication is jdbcRealm, right after I log in, glassfish automatically append the my-project-war on my URL. So

www.myhost.com will prompt me to login

right after I login, it became

www.myhost.com/my-project-war

why is that?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top