main website home
  • About this blog

    This blog features updates, opinions, and technical notes from Caucho engineers about Caucho products, the enterprise Java industry, and PHP. Caucho Technology is the creator of the Resin Application Server and the Quercus PHP in Java engine. A leader in Java performance since 1998, Caucho is a Sun JavaEE licensee with over 9000 customers worldwide.
  • Tags

    ajaxworld bam candi cdi cloud cluster comet configuration deploy devoxx eclipse ejb embedded flash flex google app engine hessian hmtp ioc java ee 6 javaone javazone jms messaging newsletter nyjug osgi php pomegranate quercus resin resin 4.0 REST servlet sfjug silicon valley code camp spring testing training tssjs watchdog webbeans web profile websockets wordpress
  • Meta

    • Register
    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
« TSSJS roundup
Getting past the “Cloud Computing” Hype »

Using nginx with Resin

There was a lively discussion a couple of weeks ago on the Resin interest mailing list about why people are using Apache with Resin and whether it’s actually necessary. Of course, we recommend that our users use Resin as both the HTTP server and the app server, but sometimes that’s not possible because of other legacy apps, non-Java apps on the same host, or simply internal politics. The trend in the non-Java world lately has been to move away from Apache to nginx because of its simple configuration and raw speed. For backend applications, it uses simple proxying or FastCGI instead of the mod_* model of Apache. I decided to check out nginx this morning and see how to hook up Resin. Turns out that it’s pretty easy!

What I tried was to run WordPress on Quercus and Resin, with nginx on the frontend. The setup for Resin is essentially the default included configuration with Resin listening on port 8080. I set up nginx to listen on port 80 and proxy all the connections to Resin at 8080. nginx serves specified static files while Resin does the rest. Here’s the nginx configuration:

user nobody nogroup;
worker_processes  4;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    gzip  on;

    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass         http://127.0.0.1:8080/;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }

        location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
            root   /var/www/hosts/default/webapps/ROOT;
        }
    }
}

I did a quick round of load testing by using ApacheBench (ab), doing 10000 requests with concurrency of 4. nginx appears to be quite efficient, introducing only about 4% overhead on top of Resin. If you need to run other non-Java applications side-by-side, nginx might be a better choice for you than Apache. I tried varying the number of worker_processes from 1 to 4 and found no significant difference in performance for my little test, but it may matter in production.

The advantage of using mod_caucho is that it provides load balancing based on number of connections, grabs the cluster configuration from a Resin instance in the backend, and provides failover. Nginx doesn’t have automatic configuration from Resin, but it appears that there are efforts to provide failover and connection-based load balancing.

Does anyone else have experience using nginx with Resin? If so, please comment below and let us know if you have any tips or best practices. I may be including some instructions in the next revision of the Resin documentation that I’m working on, so any tips would be useful.

Tags: apache, nginx

This entry was posted on Monday, March 23rd, 2009 at 1:55 pm and is filed under Engineering. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.


Caucho Technology is proudly powered by WordPress and Quercus®
Entries (RSS) and Comments (RSS).

  • HOME |
  • CONTACT US |
  • DOCUMENTATION |
  • BLOG |
  • WIKI 4 |
  • WIKI 3 |
  • Resin: Java Application Server
Copyright (c) 1998-2012 Caucho Technology, Inc. All rights reserved.
caucho® , resin® and quercus® are registered trademarks of Caucho Technology, Inc.
resin® is a cloud optimized, java® application server that supports the java ee webprofile ®