July 07, 2009

Experiments with Nginx

Lighter, smaller, faster, better? Nginx in action

There's no doubt that the Web runs on Apache. According to NetCraft, 47.1 percent of all Web sites are running on the crown jewel of the open source movement. Microsoft's IIS is a distant second at 24.8 percent, down a whopping 3.6 percent from last month. At third is qq.com, thanks to China, Google's fourth, and Nginx is fifth, running 3.7 percent of all Web sites. Nginx hasn't even been around for more than a few years, and it has only recently garnered any real interest. You'll be hearing much more about it, however. Nginx (or Engine-X) is a very impressive piece of code, currently running large sites like wordpress.com.

The whole impetus of Nginx is to be lighter, faster, and less resource intensive than Apache. To do this, it necessarily jettisons lots of functionality in favor of raw speed. For instance, Nginx can't handle CGI requests itself, so it proxies to another handler, like spawn-fcgi. But that's the idea -- you only need to run exactly what you need to run, without spending time and effort to pare Apache down to the bare essentials. In accordance to that design, a default Nginx installation has a very minimalist configuration that works fantastically for static Web tasks such as static HTML, style sheets, images, and so forth. For large sites that have dedicated image servers, it's not outside the realm of possibility that you could double the RPS from that server simply by moving to Nginx from Apache.

[ Stay up to date on the latest open source developments with InfoWorld's Technology: Open Source newsletter. ]

But what if you do need to push Nginx past simple static serving, into more advanced areas like URL rewriting, CGI tasks, and so forth? It can be done, though sometimes it gets, well, interesting. To start, let's look at a baseline Nginx configuration for a fairly beefy box:

user  www www;

worker_processes 2; pid /var/run/nginx.pid; # [ debug | info | notice | warn | error | crit ] error_log /var/log/nginx.error_log info; events {    worker_connections 2000;    # use [ kqueue | rtsig | epoll | /dev/poll | select | poll ] ;   use kqueue; }

This sets the user to run Nginx as, the error logs, the number of Nginx processes, and worker connections (note that I'm using kqueue here since this is a FreeBSD box). Pretty simple. Now, let's tweak some other settings:

additional resources
White Paper - How to Improve Delivery of Advanced Web Applications

White Paper

Virtual Workforce: The Key to Expanding The Business While Cutting Costs

Get the independent advice and expertise you need to support a virtual workforce.

Go inside:
The three-step approach to making a virtual workforce a reality.
The four flavors of client virtualization technologies.
The three key initiatives that solve IT challenges.
Download now »
White Paper: Successfully Secure Your Wireless LAN With Wi-Fi firewalls.

White Paper

Addressing Linux Threats Leveraging Fewer Resources

The increase in Linux popularity has increased the frequency and sophistication of malware attacks. Read this 2 page white paper now to learn how you can protect your Linux environment with real-time protection that is certified by all major Linux vendors.

Download now »
White Paper - The 2009 Handbook of Application Delivery

White Paper

The 2009 Handbook of Application Delivery

Ensuring acceptable application delivery will become even more difficult over the next few years. As a result, IT organizations need to ensure that the approach that they take to resolving the current application delivery challenges can scale to support the emerging challenges. This handbook elaborates on the key tasks associated with planning, optimization, management and control and provides decision criteria to help IT organizations choose appropriate solutions.

Download now »
White Paper - Is Your Backup System Outdated?

White Paper

Mid-range Storage Considerations

A common misconception is that mid-range storage requirements are dramatically different than that of a larger enterprise. Mid-range storage users may require less capacity, but they have similar functionality and management requirements. This ESG paper examines mid-range storage needs and reviews a new solution that adjusts size while retaining value, performance and functionality.

Download now »

Sign up to receive InfoWorld Resource Alerts

Subscribe to the Today's Headlines: First Look Newsletter

Find out what will be news for the day, with our first-thing-in-the-morning briefing.

©1994-2010 Infoworld, Inc.