Blog, Software Engineering

Tomcat 7 and Nginx on Ubuntu 10.12

Earlier last week, I installed Nginx with a Tomcat on a newly installed Ubuntu VPS. Unfortunately, although it comes with a lower memory footprint, it was noticably slower than my earlier Apache installation. It seemed like the simple proxying that I had in place was too slow. I decided to give the “APR based Apache Tomcat Native library” a try. Here’s what I did.

For the record, my standard proxy configuration for Nginx looks like that:

server {
        listen myserver.com:80;
        server_name myserver.com;
        location / {
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://127.0.0.1:8080/;
        }
}

1. Install dependencies
apt-get install libaprutil1-dev
apt-get install make

2. Build and install
export JAVA_HOME=...
cd tomcat/bin/tomcat-native-1.1.27-src/jni/native
./configure --with-apr=/usr
make
make install

3. Start Tomcat
Although successfully built and installed, Tomcat couldn’t find the native library at the first start:
Mar 04, 2013 1:39:51 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

I had to create a symlink in /usr/lib:
/usr/lib # ln -s /usr/local/apr/lib/libtcnative-1.so libtcnative-1.so
Now everything worked as expected:
Mar 04, 2013 1:43:15 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.27 using APR version 1.4.6.
Mar 04, 2013 1:43:15 PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Mar 04, 2013 1:43:15 PM org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized (OpenSSL 1.0.1c 10 May 2012)