3

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?

Thang Pham
  • 38,125
  • 75
  • 201
  • 285

5 Answers5

6

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.

Brian Leathem
  • 4,609
  • 1
  • 24
  • 44
  • Thank you. I am reading it now. Finally, I feel like I can tackle this problem. – Thang Pham Jan 11 '11 at 04:36
  • Right now I will settle with run gf as root. I will further invest on your blog later. I have a question, and I hope u can help me. Right now I successfully load my project when I type myhost.com. However, I use jdbcRealm as my security authentication. right after I log in, glassfish automatically append the my-project-war on my URL. So my URL become myhost/myproject-war/index.jsf. Now if I manual change my addr to myhost.com/index.jsf, it still work. I dont want the project name on the addr at all. I try to change the context root to `/` in sun-web.xml but no luck. Any idea how to fix this – Thang Pham Jan 12 '11 at 04:40
  • Sorry, I overlooked the 2nd part of your question. I edited my answer with a couple of suggestions. – Brian Leathem Jan 12 '11 at 06:41
  • The iptables was very useful! – Quaternion Jan 13 '11 at 06:59
0

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.

George
  • 4,029
  • 2
  • 22
  • 26
0

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.

ams
  • 60,316
  • 68
  • 200
  • 288
  • I think that is Glassfish v2. In v2, its role was to serve HTTP requests in front of the Tomcat based WebContainer. In v3, Grizzly is used as an extensible micro-kernel which handle almost all real time operations including dispatching HTTP requests to the Grizzly’s Web based extensions. So I dont think that will work. – Thang Pham Jan 10 '11 at 09:26
0

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).

Jubal
  • 8,357
  • 5
  • 29
  • 30
  • Can you explain more on how to do it. I do have an apache server. How do I make it speak to the Glassfish server on port 8080 – Thang Pham Jan 10 '11 at 08:48
0

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?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Thang Pham
  • 38,125
  • 75
  • 201
  • 285