Mastering Nginx

(Ron) #1
Chapter 5

[ 101 ]

Be careful, though, that the upstream servers can usually respond within the time


set by the timeout, or NGINX may deliver a 504 Gateway Timeout Error when no
upstream servers respond within this time.


Reverse proxy performance tuning


NGINX can be tuned in a number of ways to get the most out of the application
for which it is acting as a reverse proxy. By buffering, caching, and compressing,


NGINX can be configured to make the client's experience as snappy as possible.


Buffering


Buffering can be described with the help of the following figure:


The most important factor to consider performance-wise when proxying is buffering.
NGINX, by default, will try to read as much as possible from the upstream server as


fast as possible before returning that response to the client. It will buffer the response
locally so that it can deliver it to the client all at once. If any part of the request from


the client or the response from the upstream server is written out to disk, performance


might drop. This is a trade-off between RAM and disk. So it is very important to
consider the following directives when configuring NGINX to act as a reverse proxy:


Table: Proxy module buffering directives

Directive Explanation
proxy_buffer_size The size of the buffer used for the first part
of the response from the upstream server,
in which the response headers are found.
Free download pdf