Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `expires -1` mean in NGINX `location` directive?

Given the sample location example below, what does -1 mean for expires? Does that mean "never expires" or "never caches"?

# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
  expires -1;
  access_log logs/static.log;
}

https://github.com/h5bp/server-configs-nginx/blob/b935688c2b/h5bp/location/expires.conf

like image 476
Joshua Powell Avatar asked Jun 18 '15 17:06

Joshua Powell


People also ask

What is location directive in nginx?

The location directive within NGINX server block allows to route request to correct location within the file system. The directive is used to tell NGINX where to look for a resource by including files and folders while matching a location block against an URL.

What is Nginx location block?

A location block lives within a server block and is used to define how Nginx should handle requests for different resources and URIs for the parent server. The URI space can be subdivided in whatever way the administrator likes using these blocks.

What is Server_tokens Nginx?

Context: http , server , and location. This directive allows you to define whether or not Nginx should inform clients of the running version number. There are three situations where Nginx indicates its version number: In the server header of HTTP responses (such as nginx/1.8.


2 Answers

If expires -1 is used, it means that these pages are never cached. The expire directive instructs the browser to expire file cache after a certain amount of time (or at a certain time). If a negative value is given, there is no caching.

like image 52
steve klein Avatar answered Sep 29 '22 00:09

steve klein


According to nginx manual, this directive adds the Expires and Cache-Control HTTP header to the response.

Value -1 means these headers are set as:

Expires: current time minus 1 second

Cache-Control: no-cache

So in summary it instructs the browser not to cache the document.

like image 24
Marki555 Avatar answered Sep 29 '22 02:09

Marki555