4 ms·
Apache was designed in an era where the webserver did everything, and most of what it was doing was serving static content. And the fundamental design of apache
by InclinedPlane 14y ago
Apache was designed in an era where the webserver did everything, and most of what it was doing was serving static content. And the fundamental design of apache as well as the design of its configuration system is optimized for that. And though it's been modified extensively to do everything a modern web server needs to do in many ways it's still held back by that heritage. Also, apache is fairly monolithic. The way to add functionality to apache is generally with modules, for example, and generally a random apache installation is going to have vastly more features active than you may actually need, or want. All of which affects performance.
Nginx was written from the ground up in the modern web era, when we had already learned about the common ways that real websites worked (dynamic, high throughput, tied into other technology like php or rails, possibly living on multiple servers, etc.) Nginx is designed for efficiency and low overhead. It's also designed to live within an ecosystem rather than live as the container of an ecosystem, at its heart it's not a web-server it's a proxy. And all of this makes nginx easier to set up, easier to configure, and generally more efficient with superior performance compared to apache.
Here's an example. I have a server set up with a couple different sites, some of them are fronted by varnish (for caching), several run on php, and another runs on rails. With nginx this is all fairly easy to do. Instead of installing modules as you would tend to do with apache you set up php and rails as standalone socket-based servers (e.g. php-fpm and unicorn) and then in your nginx configuration you simply tell the web server where those are and how to use them.
Nginx also funnels you into a pattern which makes it easier to scale. Because nginx is just part of an ecosystem and not the container of an ecosystem you can easily migrate components to other servers as necessary. In my example I could push varnish off to another server, push each php app off onto its own server, push rails off onto separate servers, etc. The configuration changes would be fairly minimal and it would all still just work.
- smcnally 14y agoNice. After many years of apache, I, too, already use nginx. This is helpful, still. "funnels you into a pattern" is especialy good. Thank you.
- 1SaltwaterC 14y agoI'd argue a little with the "Apache is monolithic". If you know your elbow from your butt, you can make a decent Apache setup as any decent sysadmin should do. The thing that I hate the most in nginx is the lack of DSO modules. When I need a new module, I need a new nginx build. nginx itself has more than you ask for in a standard build. As example, I counted the "with" and "without" flags from out nginx package build script. It has 3 "with" flags (SSL, gzip static, PCRE JIT) vs 14 "without" flags. And we can part with gzip static since most of the static objects are pushed by CDN's now. Apache is catching up with its evented MPM and proxy support, but I still wouldn't go back to Apache though. The main selling point that the OP should get is the fact that evented servers have much better memory usage under the same load as the threaded servers or (cough) process based servers.