Monday, January 31, 2011

Creating Secure Site in Tomact and Apache

Apache Tomcat

Apache Tomcat is an open source software implementation of the Java Servlet and Java Server Pages technologies. The Java Servlet and Java Server Pages specifications are developed under the Java Community Process.
Apache Tomcat is developed in an open and participatory environment and released under the Apache License version 2. Apache Tomcat is intended to be a collaboration of the best-of-breed developers from around the world. We invite you to participate in this open development project. 

Installation of Apache Tomcat

Downloads the tar file for

http://apache.cs.utah.edu/tomcat/tomcat-6/v6.0.30/bin/apache-tomcat-6.0.30.tar.gz

tar -zxvf  Apache-tomcat-6.0.30.tar.gz
cp -r   tomcat /opt/tomcat

and write a start up scripts
create a file tomcat in /etc/init.d  give chmod 777 permissions to tomcat file
copy the 

#!/bin/bash
# chkconfig: - 10 20
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
PATH=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/bin:$PATH:$HOME/bin:./
export PATH
 export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre
export CLASSPATH=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/lib/tools.jar:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/lib/dt.jar:./
export CATALINA_HOME=/opt/tomcat/
export CATALINA_TMPDIR=/opt/tomcat/temp
unset USERNAME

start()
{
cd /opt/tomcat6/bin/
sh startup.sh
}
stop()
{
cd /opt/tomcat/bin/
sh shutdown.sh
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "start | stop | restart"
esac

save the file

and  start tomcat  /etc/init.d/tomcat start
and stop tomcat /etc/init.d/tomcat stop

http://localhost:8080

to create Secure site https

goto 
cd /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/bin

keytool -genkey -alias name-keypass admin123  -keystore domainnamecom.bin -storepass admin123
Note:keypass  and storepass  must be same password
it generate a file with name domainnamecom.bin in same directory
copy the file domainnamecom.bin to /opt/tomcat/webapps

and Goto cd /opt/tomcat/conf

and edit server.xml

and uncommmnet

   
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" keystoreFile="../webapps/domainnamecom.bin" keystorePass="admin123"  />

and save the server.xml
and restart the tomcat server

https://localhost:8443


Apache Server

The Apache HTTP Server Project is a collaborative software development effort aimed at creating a robust, commercial-grade, feature ful, and freely-available source code implementation of an HTTP (Web) server. The project is jointly managed by a group of volunteers located around the world, using the Internet and the Web to communicate, plan, and develop the server and its related documentation. This project is part of the Apache Software Foundation. In addition, hundreds of users have contributed ideas, code, and documentation to the project. This file is intended to briefly describe the history of the Apache HTTP Server and recognize the many contributors. 

Compiling and Installing
Downloads source tar http://httpd.apache.org/download.cgi
tar -zxvf  httpd-NN.tar
cd httpd
./configure --prefix=PREFIX
make
make install

configuration file is in 
/etc/httpd/conf/httpd.conf


to start
/etc/init.d/httpd start
to stop
 /etc/init.d/httpd stop 

and in browser 

http://localhost


To Create secure site 
install mod_ssl and open_ssl

then generate a key file
 openssl genrsa -out /etc/httpd/ssl/domain.com.key 1024

and using the key file generate certiifcate for 999 days

openssl req -new -key /etc/httpd/ssl/domain.com.key -x509 -out /etc/httpd/ssl/domainname.crt -days 999

and edit the /etc/httpd/conf/httpd.conf

 copy the lines

DocumentRoot "/var/www/html/ssl_doc_root/"
ServerAdmin you@mycorp.com
ServerName servername
SSLEngine On
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /etc/httpd/ssl/domain.crt
SSLCertificateKeyFile /etc/httpd/ssl/domain.com.key
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0


save the file
restart the httpd server


and in browser

https://localhost
 

No comments:

Post a Comment