Thursday, February 03, 2011

Linode: how to install mod_jk, tomcat behind apache

This "tutorial" is for Ubuntu 10.04 LTS (Lucid).
This is how you would set up Tomcat6 behind Apache2 via mod_jk

I am assuming that you have apache2 installed and tomcat6 installed. I also assume you have deployed and can find your tomcat app possibly on port 8080 of your linode.

  1. Install mod_jk:
    apt-get install libapache2-mod-jk
  2. Create workers.properties in /etc/apache2/ and add the following into it:
    # this lives in /etc/apache2/workers.properties
    # workers.properties - ajp13
    #
    # List workers
    worker.list=worker1
    
    # Define worker1
    worker.worker1.port=8009
    worker.worker1.host=localhost
    worker.worker1.type=ajp13
    
  3.  Edit your apache2 config in /etc/apache2/apache2.conf and add this to the end:
    # tomcat connector stuff:
    JkWorkersFile /etc/apache2/workers.properties
    # Where to put jk shared memory
    JkShmFile     /var/log/apache2/mod_jk.shm
    # Where to put jk logs
    JkLogFile     /var/log/apache2/mod_jk.log
    # Set the jk log level [debug/error/info]
    JkLogLevel    info
    # Select the timestamp log format
    JkLogStampFormat "[%a %b %d %H:%M:%S %Y] 
    
  4. In your /etc/apache2/sites-enabled/ dir find the vhost you want to use tomcat and edit it, at the end of the vhost declaration put:
    #Everything under root goes to tomcat
    JkMount  /* worker1
    #html files should be served by apache2
    JkUnMount /*.html worker1
    
  5. Edit /etc/tomcat6/server.xml and make sure that the ajp connector is uncommented:
    <connector port="8009" protocol="AJP/1.3" redirectport="8443" />
    
  6. restart tomcat: /etc/init.d/tomcat6 restart
  7. restart apache: /etc/init.d/apache2 restart
  8. navigate to yourdomain.com/ and you should be all tomcatted

10 comments:

  1. Much appreciated! Very helpful!

    ReplyDelete
  2. Indeed...very helpful and succint..cheers!!

    ReplyDelete
  3. Thanks! Very helpful, simple and straightforward!

    ReplyDelete
  4. I have just installed mod_jk on my Apacahe Tomcat server, thank you guidance on this install.

    ReplyDelete
  5. Very Helpful, This is exactly what I was looking for.
    But how can I make only redirect a VirtualHost and not all requests to Apache to Tomcat

    ReplyDelete
  6. getting error
    Invalid command 'JkWorkersFile', perhaps misspelled or defined by a module not included in the server configuration
    Action 'configtest' failed.
    The Apache error log may have more information.
    ...fail!

    ReplyDelete
  7. * This error drove me crazy!!!
    Syntax error on line 9 of /etc/apache2/httpd.conf:
    JkWorkersFile only allowed once
    Action 'configtest' failed.
    The Apache error log may have more information.
    ...fail!

    *To solve this,
    $ sudo vim /etc/apache2/mods-enabled/jk.conf
    # JkWorkersFile /etc/libapache2-mod-jk/workers.properties

    ReplyDelete
  8. Thank you very much ! Appreciated..

    ReplyDelete
  9. Thanks a lot. Quick Google > Found this article > Problem solved

    ReplyDelete