Static Content Caching With NGINX

Jun 27, 20162831Andrey Matveev
Static Content Caching With NGINX

NGINX is a powerful tool for static content delivery (ex. images, JavaScript, CSS, etc.). It proposes a simple mechanism for caching on a client’s side allowing to reduce server load and increase content delivery speed.

Below an example of server configuration is shown.

Let us examine it.

We specify the port which should be used by our caching proxy (NGINX):

We specify website URL:

Then we configure directory where server should look for the static files:

In order to serve the dynamic content properly we specify the following instructions that allow sending query and IP variables:

Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey

The next step will be to define processed extensions of static content files.

We disable logging of static content (increases content delivery speed and reduces the size of log files).

Further on we enable gzip compression:

Most favorable compression size is 5. This can be seen from the table below:

Compression rate Number queries per second Compressed size(original 170kb)
1 370 51,7
2 350 48,9
3 294 45,7
4 242 44,2
5 181 41,3
6 134 39,7
7 115 39,5
8 103 39,4
9 102 39,4

Later we specify cache lifetime:

The next step is to specify caching area:

Directive «private» allows only browser caching, while «public» option tells to any invisible proxies to cache our content as well (more about Cache-Control header).

Then we try to deliver the requested file or if it is not found — pass request to the dynamic processor:

In the end we should specify server address for processing dynamic content:

The NGINX configuration for static content delivery is finished.

Partner With Us Looking for a partner that will help you to grow your business? We are the right company to develop your webstore. Feel free to get in touch with us. We will be happy to discuss your business opportunities and provide you with a Free Quote. Talk to Andrey

1 comment

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *