martes, 7 de diciembre de 2010

Hide Glassfish behind an Apache server. Avoid typing server port and application name!

When you deploy a WebModule in Galssfish you can access the application using an URL like:

http://mydomain.com:GlassfishServerPort/MyWebApp-war

Typing the port of the glassfish domain and WebApp name can be really annoying. You can follow the next steps to create an aliase subdomain to access in an easier way your application.

First of all you need to configure your subdomains contacting your DNS provider. This is the only step I can't explain in detail because is very dependant of your DNS provider. In this example we will be using the subdomain "subdomain".

subdomain.mydomain.com

If your DNS is correctly configured you should be able to ping this URL and get response.

The next step is configuring a Virtual Host in APACHE for this subdomain.

-Go to /etc/httpd/conf/httpd.conf (Or any place where you have the global APACHE configuration file)
-Go to last line and write:

<VirtualHost *:80>
ServerName subdomain.mydomain.com
ProxyPass / http://subdomain.mydomain.com:GlassfishServerPort/
ProxyPassReverse / http://subdomain.mydomain.com:GlassfishServerPort/
</VirtualHost>

After restarting HTTPD service you should be able to navigate to subdomain.mydomain.com and get the Glassfish welcome page. This is good but, it would be better an instant redirection to our app. To achive this you need to execute this command in your glassfish domain to asign the defaul app for the server:

asadmin set server.http-service.virtual-server.server.default-web-module=MyWebApp-war#MyWebApp-war.war

You can even configure this usign the web admin console. (Configuration->HTTP Service->Virtual Servers).

That's it, now you have a cleaner an easier way to access your app, and your clients will be really thankfull.

No hay comentarios:

Publicar un comentario