Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a GlassFish instance running different services on different ports. An Apache web server sits in front of the GlassFish, and I want to set up virtual hosts on Apache to redirect to certain ports on the GlassFish server.

I've added the Tomcat AJP as a jvm-option to listen on port 8009 and placed the necessary .jars under lib/.

How can I configure GlassFish to redirect from port 8009 to a given port (service) on the same instance?

share|improve this question

3 Answers 3

Instead of using ajp, I would recommend using mod_proxy. I have done that myself with great success. The way I have my stuff set up, I just configure a virtual domain to point to a directory, and create a .htaccess file as such:

ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

Of course, alter to match your HTTP ports. In tomcat (which I use), I also edit in server.xml under conf. For the Connector on port 8080, I set the proxyName to match the virtual host, and the proxyPort to 80.

I should add a note that I am using dynamic virtual hosts for my configuration, my sites configuration (I am using debian) under /etc/apache2/sites-available looks as such:

<VirtualHost IP>
ServerAlias *

UseCanonicalName Off

LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon

CustomLog /var/www/ vcommon
ErrorLog /var/www/
TransferLog /var/www/

RewriteLogLevel 2

VirtualDocumentRoot /var/www/
VirtualScriptAlias /var/www/

LogLevel debug

<Directory /var/www/>
  AllowOverride All


This means that will go to /var/www/

I know you didn't ask for the last part, I just provided it to give a full overview off my setup, and how it fits into the .htaccess file with ProxyPass and ProxyPassReverse

share|improve this answer
We're using mod_proxy over AJP in place also. I find it much more straightforward to setup. What are the benefits of AJP (if any) I wonder? Is it better from a performance perspective? – stephen mulcahy Jun 2 '09 at 11:03

You can use Apache to point to several different servers of varying types.

# Drop me in a file called my_proxies.conf in conf.d
# Apache picks up everything in conf.d/*.conf

NameVirtualHost *:80

<VirtualHost *:80>

# This Apache serves up images and cgi-bin
ProxyPass /images !
ProxyPass /cgi-bin !                                        
# Got stuff on this server (Jetty, Glassfish, Tomcat, or Apache )
ProxyPass /foo http://localhost:8080/foo
ProxyPassReverse /foo http://localhost:8080/foo
Redirect /foo http://localhost:8080/foo
ErrorLog /tmp/foo_error_log
CustomLog /tmp/foo_access_log
# Root comes last
# Let's put our main app on its own special server
ProxyPass / http://localhost:9090/
ProxyPassReverse / http://localhost:9090/
ErrorLog /tmp/bar_error_log
CustomLog /tmp/bar_access_log
share|improve this answer

I would suggest you to use an Apache module mod_loadbalancer, which was specially implemented for the use with Glassfish application server and is capable of reacting to Glassfish app server configuration commands initiated from the admin console.

See the example -

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.