Wednesday, July 31, 2013

Enable SSL for Apache Httpd - Tomcat


Follow the steps below to achieve ssl (or https):

  1. Enable ssl module on apache : sudo a2enmod ssl (the ssl mod config is usually located @ /etc/apache2/mods-available)
  2. Edit the /etc/apache2/sites-available/default-ssl file. Add the following lines:
    • ProxyPass /payment         ajp://<your website url>/<sub folder to redirect> (e.g. ajp://anant.apnapaisa.com/payment)
    • ProxyPassReverse /payment   ajp://<your website url>/<sub folder to redirect>  )e.g. ajp://anant.apnapaisa.com/payment)
  3. Add the below lines to enable images, scripts and styles to be served via https.
    • Alias /<path to scripts> /<Complete path to scripts> (e.g. /scripts /home/anant/code/tomcat/webapps/als/scripts)
    • Alias /<path to styles>/style /<Complete path to sty;es> (e.g. /home/anant/code/tomcat/webapps/als/style)
    • Alias /<path to images> /<Complete path to imagess> (e.g. /images/ /home/anant/code/tomcat/webapps/als/images/)
  4. Save the file and enable the default-site: sudo a2ensite default-ssl
  5. Try running https://localhost. Ignore the security warning your browser displays (if it displays any). You should reach the "It Works" page.
  6. In your tomcat conf/server.xml, uncomment the line:

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"

                       maxThreads="150" scheme="https" secure="true"                       clientAuth="false" sslProtocol="TLS" />

You should now be able to direct https request to your servlets deployed on tomcat.

Note: The proxy settings are for ajp connector. Use the appropriate protocol for http connector.