Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure ETag on Nginx

I'm using Nginx as a webserver and want to implement a browser caching method so that the users keep copies of static unchanged files locally and download only changed files. One of the propositions was to use the files timestamp to figure out the changed files and refresh them only, but this is not possible in my case since after every new deploy a new version of the whole web application is created and all the files' timestamps change.

I researched a little about the ETag header, and it seemed as a pretty good solution, but I found out that Etags are not officially supported by Nginx yet.

Are there any way of implementing the Etags on Nginx or any alternative solutions?

like image 875
HanouaJ Avatar asked Jul 03 '14 09:07

HanouaJ


People also ask

How do I add cache-control headers in nginx?

If you want to enable Cache-Control for all files, add a add_header line without the enclosing location block, as what the location block does is specify specific filetypes you are targeting with your directives (ico,pdf,flv etc.).

How do I enable caching in nginx?

Go to the “Web Server” tab. In the “nginx settings” section, select the “Enable nginx caching” checkbox. (Optional) You can customize nginx caching settings. If you are not familiar with nginx caching, we recommend that you keep the default settings.

Does nginx support caching?

Specifying Which Requests to CacheBy default, NGINX Plus caches all responses to requests made with the HTTP GET and HEAD methods the first time such responses are received from a proxied server. As the key (identifier) for a request, NGINX Plus uses the request string.


1 Answers

Upgrade your Nginx.

Syntax:     etag on | off; Default:    etag on;  Context:    http, server, location  This directive appeared in version 1.3.3.  Enables or disables automatic generation of the “ETag” response header field for static resources. 

Source: http://nginx.org/en/docs/http/ngx_http_core_module.html#etag

like image 178
Tan Hong Tat Avatar answered Sep 19 '22 15:09

Tan Hong Tat