4

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?

3 Answers3

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

Staale
  • 131
  • 1
  • 5
  • 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? –  Jun 02 '09 at 11:03
0

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>
0

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

kairius
  • 101