SWAT Blog

Setting up Glassfish Server Behind Apache https

May 7th, 2015 by Bhagwan Dass

Installing Glassfish and Deploying one sample.war application:

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


mint-pc~#GLASSFISH_HOME/glassfish/bin/./asadmin start-domain

This command will start the default domain included in the server, which is called domain1.
After a few seconds, you should be able to browse to its default page at http://server-ip:8080 or the Web Admin Panel at http://server-ip:4848.

After this, we’ll use the asadmin commnad to to add an http listener called jk-connector-8009, which will listen on port 8009 for AJP connections.
This is the port that Apache will use to redirect requests from port 80 to Glassfish, and back to Apache.

Create the listener:

mint-pc~#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

Activate the listener:

mint-pc~#GLASSFISH_HOME/glassfish/bin/./asadmin --user admin --host localhost --port 4848 setconfigs.config.server-config.network-config.network-listeners.network-listener.jk-connector-8009.jk-enabled=true

Finally, restart the Glassfish Server:

mint-pc~#GLASSFISH_HOME/glassfish/bin/./asadmin stop-domain

mint-pc~#GLASSFISH_HOME/glassfish/bin/./asadmin start-domain

Configuring Apache:
Installing and configure Apache2 and mod_jk:–

mint-pc~#apt-get install libapache2-mod-jk

Installing mod_jk this way will ensure that the mod_jk module is enabled for Apache2. You can check and verify that with:-

mint-pc~#ls -l /etc/apache2/mods-enabled/jk.load (Should show like below line)

lrwxrwxrwx 1 root root 25 2009-08-12 14:18 /etc/apache2/mods-enabled/jk.load -> ../mods-available/jk.load

In case the module is missing from the monds-enabled directory, enable it with:

mint-pc~#a2enmod jk

Run this command on terminal:-

mint-pc~#grep -r JkWorkersFile /etc/apache2 (Default workers.properties file path)

/etc/apache2/mods-available/jk.conf: JkWorkersFile /etc/libapache2-mod-jk/workers.properties

Put Below mentioned text in workers.properties file.
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300

A file called /etc/apache2/mods-available/jk.conf (Should have below text)
# Where to find workers.properties
JkWorkersFile /etc/libapache2-mod-jk/workers.properties
# Where to put jk logs
JkLogFile /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info

The only thing to do is to specify which URL paths should be redirected to mod_jk.
I added these lines to /etc/apache2/sites-enabled/000-default.conf within the <VirtualHost></VirtualHost> tags:

# Send everything for context /examples to worker named worker1 (ajp13)
JkMount /* worker1

Finally restart apache2:-

mint-pc~#/etc/init.d/apache2 restart

Tested in Firefox and Chrome working:-
http://localhost/sample/
http://localhost:8080/sample/

Create a SSL Certificate on Apache for Ubuntu 14.04

mint-pc~#apt-get update

mint-pc~#apt-get install apache2

Activate the SSL Module:-

mint-pc~#a2enmod ssl

mint-pc~#service apache2 restart

Create a Self-Signed SSL Certificate:-

mint-pc~#mkdir /etc/apache2/ssl

Now that we have a location to place our key and certificate, we can create them both in one step by typing:

mint-pc~#openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

Hit “ENTER”, you will be asked a number of questions:-
The questions portion looks something like this:
Country Name (2 letter code) [AU]:IN
State or Province Name (full name) [Some-State]:U.P.
Locality Name (eg, city) []:Noida
Organization Name (eg, company) [Internet Widgits Pty Ltd]:SW-AT
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:www.curowin.com
Email Address []:admin@sw-at.com

The key and certificate will be created and placed in your /etc/apache2/ssl directory:-

Configure Apache to Use SSL:-

mint-pc~#gedit /etc/apache2/sites-available/000-default.conf

<VirtualHost *:443>
#ServerName www.example.com

ServerAdmin webmaster@localhost
ServerName 127.0.0.1:443 #(or your domain name:443)
DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

#Send everything for context /examples to worker named worker1 (ajp13)
JkMount /* worker1

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

</VirtualHost>
#vim: syntax=apache ts=4 sw=4 sts=4 sr noet


mint-pc~#service apache2 restart

https://localhost/sample/

Leave a Reply

  • © 2004-2015 Special Work & Technology Limited