Setting up Glassfish behind Apache
After you unzip Glassfish, you can start the server by running this command:
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 0.0.0.0 --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
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
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:
... 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.