Take the 2-minute tour ×
Server Fault is a question and answer site for professional 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
add comment

3 Answers

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>
Servername yourdomain.com
ServerAlias *.yourdomain.com

UseCanonicalName Off

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

CustomLog /var/www/yourdomain.com/logs/custom.log vcommon
ErrorLog /var/www/yourdomain.com/logs/error.log
TransferLog /var/www/yourdomain.com/logs/access.log

RewriteLog/var/www/yourdomain.com/logs/rewrite.log
RewriteLogLevel 2

VirtualDocumentRoot /var/www/yourdomain.com/sites/%1/html
VirtualScriptAlias /var/www/yourdomain.com/sites/%1/cgi-bin

LogLevel debug

<Directory /var/www/yourdomain.com/sites/>
  AllowOverride All
</Directory>

</VirtualHost>

This means that stackoverflow.yourdomain.com will go to /var/www/yourdomain.com/sites/stackoverflow/html

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
add comment

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
#
</VirtualHost>
share|improve this answer
add comment

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 - https://blogs.oracle.com/kshitiz/entry/load_balancer_plugin_in_glassfish

share|improve this answer
add comment

Your Answer

 
discard

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