By far and away the most popular web server is the Apache HTTP Server (usually just ‘Apache’) – the A in LAMP. However, Apache is by no means the only web server available, and some of its downsides have led to the development of alternatives. One such example is nginx – pronounced ‘engine-ex’ and not, as I originally thought, ‘en-jinx’. FLOSS Weekly recently covered nginx in one of their podcasts, and this spurred me to write a post about what is probably the second most popular web service for Unix platforms.
First of all, nginx is not necessarily a wholesale replacement for Apache – although it can be configured as an origin server. Instead, the main selling point is its use as a reverse proxy, where nginx sits in front of one or more existing web servers and performs tasks such as load balancing and caching.
The ability to handle large numbers of concurrent requests is also a major selling point of nginx – apparently 10,000 simultaneous connections (the C10k problem) can be dealt with in a low memory footprint, though of course other hardware and software factors will influence performance.
However, nginx doesn’t win hands-down against Apache, at least not for every use case. Modules must currently be specified at compile-time, as there is no support for dynamic loading, and the range of modules available is smaller. Cross-platform support is also less mature than Apache, with the Windows port being explicitly marked as ‘beta’.
Whilst I’ve focused on HTTP in this post, nginx can also be used as a proxy for other protocols, including IMAP and SMTP. This is outside my area of expertise, but if you want to know more you can check out this talk: The Perdition and NGINX IMAP Proxies by Jan-Piet Mens.
One thing i’d put in favour of nginx is that its configuration format seems much more ‘sane’ and understandable to me. Apache config depends on sort of knowing it, and usually I copy and paste, but often I feel like I could construct an nginx config from scratch much more easily.
I’ve always found Apache’s format to be fairly simple, though that may be because I’ve used it for about 10 years now and I have a template which works for the vast majority of virtual hosts.
I’ll have to give nginx a try in the next couple of weeks to see how its configuration compares.