understanding nginx proxy magic

Francis Daly francis at daoine.org
Tue Nov 25 08:41:37 UTC 2014

On Mon, Nov 24, 2014 at 05:49:12PM -0800, Johan Martinez wrote:

Hi there,

> I installed nginx as a reverse proxy in front of apache server. No
> configuration change was made on apache and nginx is simply passing all
> requests to the backend apache. Now website is more responsive and it can
> handle 1.3 times more load than just apache in picture. I am wondering
> what's nginx magic that made website faster even though apache is still
> doing almost all the work.

If you draw a picture of what is involved in the browser making a request
and getting a response in each case, you may see the difference.

Note particularly the length of time it takes the request to be received
and the response to be sent; and consider the amount of system resources
(probably mostly memory) used to do that, for that length of time.

If it takes "the web server" 10 seconds to write the response to the
client -- just because of the response size and network characteristics
-- then the old way had one apache process sitting there for 10 seconds
writing to the network, while the new way has one apache process sitting
there for one second writing to nginx and has nginx sitting there for
10 seconds writing to the network.

The nginx process doing the writing is smaller than the apache process
was; and the apache process is ready to handle the next request 9 seconds
sooner than previously.

Presumably in your case, the overhead of running an extra service (nginx)
is less than what your apache used when doing the lightweight tasks,
so you see an increase in throughput.

Francis Daly        francis at daoine.org

More information about the nginx mailing list