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 general web, Windoze · 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);

SVNAnt does not work

September 3, 2009 · Posted in Uncategorized · Comment 

If using SVNAnt, make sure subversion is installed on the system.

In case, there is a way to use SVNAnt without it please let me know.

Invoke a servlet from a servlet

September 3, 2009 · Posted in Uncategorized · Comment 

There are couple of ways to do so:

  1. Send a HTTP request
    To invoke a servlet that requires authentication, in addition to creating the URL object, you need to pass authentication cookies too.

    URL url = new URL("http://blah");
    URLConnection con = url.openConnection();
    con.setRequestProperty("Cookie", request.getHeader("Cookie"));
    con.connect();
  2. RequestDispatcher
  3. Send a redirect

GMail down

September 1, 2009 · Posted in Uncategorized · Comment 

It has been more than an hour or so, I am unable to access gmail. I get the following error.

google-error

I wonder what made this happen!

Update: Found the problem what caused this mess on gmail’s blog

MySQL database backup and restore

July 14, 2009 · Posted in Uncategorized · Comment 

1. Create Database Backup:
You can use mysqldump to create a simple backup of your database using the following syntax.

mysqldump -u [username] -p [password] [databasename] > [backupfile.sql]

  • [username] – this is your database username
  • [password] – this is the password for your database
  • [databasename] – the name of your database
  • [backupfile.sql] – the file to which the backup should be written.

You can also ask mysqldump to add a drop table command before every create command by using the option –add-drop-table. This option is useful if you would like to create a backup file which can rewrite an existing database without having to delete the older database manually first.
mysqldump --add-drop-table -u [username] -p [password] [databasename] > [backupfile.sql]

If you want to back up certain tables
mysqldump -u [username] -p [password] [databasename] [table1] [tableN]> [backupfile.sql]

If you want to back up multiple databases
mysqldump -u [username] -p [password] [databasename1] [databasenameN] > [backupfile.sql]

Or want to back up all databases
mysqldump -u [username] -p [password] --databases-all > [backupfile.sql]

2. Restore from database backup

Restore a particular database
mysql -u [username] -p [password] [database_to_restore] < [backupfile]

Restore all databases
mysql -u [username] -p [password] < [backupfile]

Create self signing SSL Certificate

July 10, 2009 · Posted in apache · Comment 
  1. Generate server key
    openssl genrsa -des3 -out server.key 4096
  2. Create certificate signing request
    openssl req -new -key server.key -out server.csr
  3. Sign the certificate signing request with the server key
    openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
  4. Make the server key that does not need the password
    openssl rsa -in server.key -out server.key.insecure
  5. Do some house cleaning
    mv server.key server.key.secure
    mv server.key.insecure server.key
  6. Use the following files in apache configuration
    server.key
    server.crt

Force SSL on apache

July 10, 2009 · Posted in apache, linux · Comment 

mod rewrite should be enabled on apache. Add the following to your apache config file.

#########################################
#### XXX: BEGIN EDIT FOR MOD_REWRITE ####
#### This is intended to force HTTPS ####
#### for all inbound HTTP requests ####

####
# This module (mod_rewrite) simply tells Apache2 that all connections to
# port 80 need to go to port 443 – SSL – No exceptions
####


LoadModule rewrite_module modules/mod_rewrite.so


RewriteEngine on

####
# The line below sets the rewrite condition for mod_rewrite.so.
# That is, if the server port does not equal 443, then this condition is true
####

ReWriteCond %{SERVER_PORT} !^443$

####
# The line below is the rule, it states that if above condition is true,
# and the request can be any url, then redirect everything to https:// plus
# the original url that was requested.
####

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

#### XXX: END EDIT FOR MOD_REWRITE ####

Linux Disable Hardware Beep Sound For Terminal

July 8, 2009 · Posted in linux · Comment 
  • If you are using xterm, open ~/.xsession file
    $ cd
    $ vi .xession
    Append the following line:
    xset b off
    Save and close the file.
  • If you are using bash shell, open ~/.inputrc file
    $ cd
    $ vi .inputrc
    Append following line:
    set bell-style none
    Save and close the file.
  • If you want to turn off beep for VIM text editor, open vim config file ~/.vimrc
    $ cd
    $ vi .vimrc
    Append following line
    set vb
    Save and close the file.

« Previous PageNext Page »

  • Calendar

    February 2012
    M T W T F S S
    « Jan    
     12345
    6789101112
    13141516171819
    20212223242526
    272829