Generate SSL certificate for Tomcat

January 21, 2010 · Posted in general web, java · Comment 

Following are the steps to create an real SSL certificate (verified by VeriSign/Thawte etc.) for Tomcat:
1. Creation of keystore
keytool -genkey -alias XXX -keyalg RSA -keystore ./XXX.keystore

2. Generation of CSR
keytool -certreq -alias XXX -file XXX.csr -keystore ./XXX.keystore
Send the generated XXX.csr to the signing authority and get the certificate from them. Save that file as “XXX.thawte”

3. Install the certificate in the keystore
keytool -import -alias XXX -trustcacerts -file XXX.thawte -keystore XXX.keystore

That’s it.

List of Countries

January 20, 2010 · Posted in general web · Comment 

In case you need a list of countries, here is the file

Integrate Apache 2 with Tomcat 6

January 18, 2010 · Posted in apache, general web, java, linux · Comment 

I have been trying to configure apache/tomcat is such a way that apache comes on the front-end so that I can have all the features of apache like URL rewriting, virtual hosts, PHP etc. and forward only certain requests to tomcat whose only job should be running servlets.

I have CentOS installed on my server with Apache 2 installed through yum and the goal was to install the binaries for Tomcat 6 and make them talk to each other. After some googling, the best tutorial I found to configure tomcat through mod_jk was found here. I have attached the PDF of the instructions here.
After following the steps, I was easily able to create a worker and configure apache to forward the request to /examples to tomcat.
The next issue was how to configure virtual hosts so that I can host multiple websites, some handled by apache and others through tomcat. Following is the snippet of httpd.conf setting that needs to be updated to enable virtual hosting.


NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
<VirtualHost *:80>

ServerAdmin webmaster@lalitmehta.com
ServerName www.lalitmehta.com
ErrorLog logs/lalitmehta.com-error_log
CustomLog logs/lalitmehta-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin info@saiyam.com
ServerName rsspile.com
#   No need of DocumentRoot
ErrorLog logs/rsspile.com-error_log
CustomLog logs/rsspile.com-access_log common
JkMount /rss ajp13
JkMount /rss/* ajp13
</VirtualHost>


I do have two questions though:
1. since mod_jk.so is available for download for Linux, what advantage you get by compiling Apache and mod_jk from source? Most of the websites mention the need to compile the source. Let me know :)
2. How do I enable SSL on my server with the above configuration?

Increase maximum limit of open files per user

January 15, 2010 · Posted in linux · Comment 

If you want to increase the limit of open files for the current session, simply run

ulimit -n 2048

If you want to increase it by default, edit /etc/security/limits.conf and add

*    hard     nofile     2048
*    soft     nofile     2048

or if you want to increase it only for a certain user, set it as

userlogin    hard     nofile     2048
userlogin    soft     nofile     2048

IE 6 bug in window.location

January 13, 2010 · Posted in Windoze, general web · Comment 

There is a bug in IE 6 where following code does not work

var newUrl = "http://www.google.com/";
window.location = newUrl;
// This also doesn't work!
// window.location.href = newUrl;

After a scratching head for couple of hours, found the solution here

var newUrl = "http://google.com/";
setTimeout(function()
{
window.location = newUrl;
}, 0);