Install Centos Linux

Install Centos on a VM / Desktop

Install Apache

How to ensure all traffic served by SSL ?

LoadModule rewrite_module libexec/apache2/

## Forcing HTTPS for certain URLs

ProxyPass    http://*/ (http://*/   ) ; https://*:8080/


RewriteEngine on

ReWriteCond %  SERVER_PORT !^443$

RewriteRule ^/(.*) https://%   HTTP_HOST  /$1 [NC,R,L]

Enable SSL for specific APP – remeber the ‘retry’ !!!

ProxyPass    /myapp    http://localhost:8080/myapp retry=5

Configuring Apache to Use Compression

# mod_deflate (compress output for browsers that support it)
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript text/javascript text/x-js application/json application/xml application/javascript

# Some adjustments for IE browsers (

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html
BrowserMatch \bMSIE\s8 !no-gzip !gzip-only-text/html

How to implement Load Balancer ?

Ref :

Virtual Host Tomcat Connector :

Do not use mod_jk , rather use mod_proxy_ajp : 

Setup two Tomcat instances with AJP ports 8019, 8029

ProxyPass / balancer://cluster/ stickysession=JSESSIONID nofailover=On
<Proxy balancer://cluster>
BalancerMember ajp://localhost:8019
BalancerMember ajp://localhost:8029

Concrete Reference :

Set up Load Balancer with Sticky Sessions :

This site specifies certain tricks for PHP sessions.

Access you app :  http://localhost:8080/myapp

Test Load Balancer : http://localhost/balancer-manager

How to implement Virtual Redirection ?

For a simple frontend server, it is often desirable to run multiple HTTP services on the one machine. The web server is Apache, and we want different parts of the site (goverend by path) processed by different HTTP services (Apache, Tomcat, IIS).

Uncomment these lines, if not already done

AddModule mod_rewrite.c

AddModule mod_proxy.c

LoadModule rewrite_module modules/

LoadModule proxy_module modules/

Later, either within a virtual host entry or the main host entry, add your re-writing logic.

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteLog "logs/rewrite_log"
 RewriteLogLevel 0
 RewriteRule ^/gallery(.*)$1 [P]
 RewriteRule ^/aspx(.*)$1 [P, L]

This redirects all traffic matching /gallery to a Tomcat web-app ‘gallery’, where Tomcat is running on port 8080. Similarly, any requests matching /aspx are redirected to IIS, which runs on port 8090.

With this setup, both Tomcat and Apache run on ports which are blocked by the firewall.

Classic Reverse-Proxies

Use apache as the global front end.

Open up a private port for a specific application :

>> ProxyPass and ProxyPassReverse are classic reverse proxy directives used to forward the stream to another location.

>> first check if the port is available :

/sbin/ ./semanage port -l | grep 1979

>> then actually allocate it …..

semanage port -a -t http_port_t -p tcp 1979

>>>>>> Do not mess up httpd.conf — add this line at the end — Include /etc/httpd/extras/*.conf

sudo touch /etc/httpd/extras/ajp.conf;

Listen 1979
NameVirtualHost *:1979
<VirtualHost *:1979>
ServerName localhost
ErrorLog /var/log/apache2/ajp.error.log
CustomLog /var/log/apache2/ajp.log combined
<Proxy *>

AddDefaultCharset Off
Order deny,allow
Allow from all

ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/

The mod_proxy_ajp will forward you request transparently using the AJP protocol to the tomcat application server on localhost:8009.


Install MySQL


Install Tomcat and Java

Basic Configuration


SSL on Tomcat

We can place Tomcat behind an Apache Webserver or behind a Hardware Load-balancer.

Then use a native SSL or external SSL certificate (APR – more secure and advanced mechanism).

Configuring tomcat to handle SSL natively
<Connector port=”80″ protocol=”HTTP/1.1″
redirectPort=”443″ />

To make Tomcat listen on the port 443, with a SSL transport, the following needs to be configured in the server.xml file:

<Connector port=”443″ protocol=”HTTP/1.1″ SSLEnabled=”true”
maxThreads=”150″ scheme=”https” secure=”true”
clientAuth=”false” sslProtocol=”TLS”

The keystore file is created as follow:

root@server:~/$JAVA_HOME/bin/keytool -genkey -alias virtualhostname \   -keyalg RSA -keystore /opt/apache-tomcat-6.0.13/.keystore

If you need to obtain and install a certificate signed by a trusted authority, review the tomcat documentation here:

You can also take an existing X509 certificate and private key and import them into a keystore using the following utility:

Configuring tomcat to use APR

If you take the time to install APR and the tomcat native libraries, tomcat can be made to work with an X509 certificate in PEM format without conversion. Those instructions can be found at:

Configuring tomcat to force SSL for appropriate content.

At a minimum, any components (login, xlogin) that transmit username and password information should be transmitted using SSL to avoid problems with session cookie hijacking.

To secure an individual tomcat context, you must edit its WEB-INF/web.xml and add the following inside the <web-app> tags:

<!- redirect all traffic to the SSL port ->
<web-resource-name>Automatic SLL Forwarding</web-resource-name>

At a minimum, you should secure The ROOT and login contexts.

Securing All Tomcat Contexts

If you wish to secure the entire tomcat installation (which can be done regardless of how you provide SSL), add the following to TOMCAT_HOME/conf/web.xml inside the web-app tags:

<!- redirect all traffic to the SSL port ->
<web-resource-name>Automatic SLL Forwarding</web-resource-name>

If you have content that is required to be transmitted using http (for example, a tool that exports subscribable iCal calendars), you may want to relax the overall security restriction for a single context.

This can be done by adding the following to a context’s WEB-INF/web.xml file:\\

<web-resource-name>SSL Requirement Disabled</web-resource-name>

Auto-redirection to ssl port,

— uncomment AJP port in web.xml :: <Connector enableLookups=”false” port=”8009″ protocol=”AJP/1.3″ redirectPort=”8443″ URIEncoding=”UTF-8” / >

— set redirect port for http-port and ajp-port to 8443.

— inside tomcat_home/conf/web.xml :: mark all resource requests confidential …as shown above !

Install Certificate from ThirdParty