# Understanding nginx proxy magic

**URL:** <https://www.ruby-forum.com/t/understanding-nginx-proxy-magic/233214>\
**Category:** NGINX\
**Created:** [November 25, 2014, 2:50am UTC](https://www.ruby-forum.com/t/understanding-nginx-proxy-magic/233214 "2014-11-25T02:50:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [November 25, 2014, 2:50am UTC](https://www.ruby-forum.com/t/understanding-nginx-proxy-magic/233214/1 "2014-11-25T02:50:00Z")

</div>

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. I am not systems expert so any pointers on  
why  
such setup is faster will be helpful. There isn’t much configuration to  
nginx than:

location / {  
proxy\_set\_header Host [www.example.com](http://www.example.com);  
proxy\_pass [http://127.0.0.1:8080](http://127.0.0.1:8080);  
proxy\_redirect off;  
}

Reason for such simple setup is to slowly migrate from apache to nginx.

- Johan

---

<div class="post-metadata">

**Author:** ![papacostas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@papacostas](https://www.ruby-forum.com/u/papacostas)\
**Post date:** [November 25, 2014, 9:41am UTC](https://www.ruby-forum.com/t/understanding-nginx-proxy-magic/233214/2 "2014-11-25T09:41:58Z")

</div>

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.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![papacostas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@papacostas](https://www.ruby-forum.com/u/papacostas)\
**Post date:** [November 25, 2014, 2:21pm UTC](https://www.ruby-forum.com/t/understanding-nginx-proxy-magic/233214/3 "2014-11-25T14:21:13Z")

</div>

On Monday 24 November 2014 17:49:12 Johan Martinez wrote:

> ```
> proxy_set_header Host www.example.com;
> proxy_pass http://127.0.0.1:8080;
> proxy_redirect off;
> }
> 
> ```
> 
> Reason for such simple setup is to slowly migrate from apache to nginx.

Here’s a comprehensive explanation:

> **[The Architecture of Open Source Applications (Volume 2)nginx](https://aosabook.org/en/nginx.html)**

wbr, Valentin V. Bartenev
