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.
More recent articles
- llm cmd undo last git commit - a new plugin for LLM - 26th March 2024
- Building and testing C extensions for SQLite with ChatGPT Code Interpreter - 23rd March 2024
- Claude and ChatGPT for ad-hoc sidequests - 22nd March 2024
- Weeknotes: the aftermath of NICAR - 16th March 2024
- The GPT-4 barrier has finally been broken - 8th March 2024
- Prompt injection and jailbreaking are not the same thing - 5th March 2024
- Interesting ideas in Observable Framework - 3rd March 2024
- Weeknotes: Getting ready for NICAR - 27th February 2024
- The killer app of Gemini Pro 1.5 is video - 21st February 2024
- Weeknotes: a Datasette release, an LLM release and a bunch of new plugins - 9th February 2024