Simon Willison’s Weblog

Subscribe

What are the advantages of running Apache behind nginx as opposed to just Apache by itself?

12th October 2010

My answer to What are the advantages of running Apache behind nginx as opposed to just Apache by itself? on Quora

I do this for all of my Django stuff—I have Django running on modwsgi on a stripped down Apache (almost no configuration except for the modwsgi stuff), then I put an nginx on port 80 which serves the static files directly and proxies dynamic requests back to Apache.

There are a few advantages to this. Firstly, I use non-threaded Apache so each Apache worker process tends to be pretty big (having a full Python interpreter + Django application running in it). It’s a horrible waste of resources for one of those fat processes to sit around serving up a static file instead of serving a dynamic request. Secondly, nginx deals with slow connections for me—if someone on a modem (or 3G phone) hits my site I don’t tie up an Apache process for several seconds to respond to their request. Instead, nginx sucks the response in from Apache in a few ms and then spools it out to the slow client at whatever rate they can handle. Since nginx is evented it can handle hundreds or even thousands of slow clients at once using very little memory.

Finally, if I’m running an nginx proxy at the “front” of my stack it’s trivial for me to start load balancing to more than one Apache servers if I need to.

This is What are the advantages of running Apache behind nginx as opposed to just Apache by itself? by Simon Willison, posted on 12th October 2010.

Next: Where can I find a database of the cities in the United States, their populations, and square miles?

Previous: Is it not time for Google to redesign its search page by removing the "search" & "I'm Feeling Lucky" buttons since the buttons are now useless with the new "Instant" structure?

Monthly briefing

Sponsor me for $10/month and get a curated email digest of the month's most important LLM developments.

Pay me to send you less!

Sponsor & subscribe