1. Home
  2. Help Articles
  3. Setting up Glassfish behind Apache

Setting up Glassfish behind Apache

Setting up Glassfish behind Apache

After you unzip Glassfish, you can start the server by running this command:

$GLASSFISH_HOME/glassfish/bin/asadmin start-domain


The above command starts the default domain i.e domain1 and few minutes later able to browse default page http://server-ip:8080 or the web admin page http://server-ip:4848


Use asadmin command to add http listener called jk-connector-8009 which will listen on port 8009 for AJP connection. This port will be used by apacheto redirect requested from port 80 to Glassfish and back to apache


Step One : – Create the listener


$GLASSFISH_HOME/glassfish/bin/asadmin --user admin --host localhost --port 4848 create-http-listener --listeneraddress --listenerport 8009 --defaultvs server jk-connector-8009


Step Two : – Activate the listener


$GLASSFISH_HOME/glassfish/bin/asadmin --user admin --host localhost --port 4848 set configs.config.server-config.network-config.network-listeners.network-listener.jk-connector-8009.jk-enabled=true


Step Three : – Retarting Glassfish Server


$GLASSFISH_HOME/glassfish/bin/asadmin stop-domain

$GLASSFISH_HOME/glassfish/bin/asadmin start-domain




Configuring Apache

Download the Tomcat mod_jk connector ( http://tomcat.apache.org/connectors-doc/ ) and place the “.so “ file in your modules directory. (e.g. /etc/httpd/modules)

Create a file called workers.properties and place it in a safe place (e.g. /etc/httpd/conf.d). Put the following contents in this file:



Then, open your httpd.conf file and put the following contents in it (outside a “VirtualHost section”).  Check the path of your “workers.properties” file


JkWorkersFile /path/to/workers.properties

JkLogFile /var/log/httpd/mod_jk.log

JkLogLevel debug

JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

JkRequestLogFormat "%w %V %T"



Now we need to add a VirtualHost section in the page, in order to map the specific domain/subdomain with the path in Glassfish we want to make visible through Apache:


ServerAdmin webmaster@mydomain.com

ServerName mydomain.com

... other stuff

JkMount /myapp/* worker1

... other stuff



The JKMount line in above instance tells Apache that all requests that go to http://mydomain.com/myapp/ will be served by worker1, which is connected to port 8009 of localhost which is the port we opened before in Glassfish. If you want Glassfish to serve all contents of mydomain.com, change the JKMount to /* worker1

Finally, restart Apache and you’re all set! The Glassfish instance will be visible through Apache by port 80, and therefore you won’t need to open additional ports in your server.

Updated on October 28, 2016

Was this article helpful?

Related Articles

Add A Comment