Nginx tuning reverse proxy performance

By:    Updated: February 27,2017

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, such as by buffering, caching, storing, compressing, and more.

Nginx buffering

Nginx, by default, will try to read as much as possible from the upstream server as fast as possible before returning the 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.

 

By measuring the average request and response sizes going through the reverse proxy, the proxy buffer sizes can be tuned optimally. Each buffer directive counts per connection, in addition to an OS-dependent per-connection overhead, so we can calculate how many simultaneous client connections we can support with the amount of memory on a system.

Nginx caching

Nginx is also capable of caching the response from the upstream server, so that the same request asked again doesn't have to go back to the upstream server to be served.

Nginx tuning reverse proxy performance

Nginx storing

If you are serving large static files that will be never changed, there is no reason to expire the entries, then Nginx offers a store to help serve these files faster. Nginx will store a local copy of any files that you configure it to fetch. These files will remain on disk and the upstream server will not be asked for them again. If any of these files should be changed on the upstream server, they need to be deleted by some external process, otherwise Nginx will continue serving them, so for smaller static files, using the cache is more appropriate.

Nginx compressing

Nginx has the capability of compressing a response it receives from an upstream server before passing it on to the client by turning on the gzip functionality.This can help reduce a response's transfer time.

More in Development Center
New on Valinv
Sources
  • http://nginx.org/en/docs/http/ngx_http_proxy_module.html
  • http://nginx.org/en/docs/http/ngx_http_gzip_module.html
Related Articles
Sponsored Links