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
- Slop is the new name for unwanted AI-generated content - 8th May 2024
- Weeknotes: more datasette-secrets, plus a mystery video project - 7th May 2024
- Weeknotes: Llama 3, AI for Data Journalism, llm-evals and datasette-secrets - 23rd April 2024
- Options for accessing Llama 3 from the terminal using LLM - 22nd April 2024
- AI for Data Journalism: demonstrating what we can do with this stuff right now - 17th April 2024
- Three major LLM releases in 24 hours (plus weeknotes) - 10th April 2024
- Building files-to-prompt entirely using Claude 3 Opus - 8th April 2024
- Running OCR against PDFs and images directly in your browser - 30th March 2024
- 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