FAQ

Page Discussion History

Difference between revisions of "HttpHeadersModule"

(Directives)
(Directives)
Line 16: Line 16:
 
= Directives =
 
= Directives =
 
== add_header ==
 
== add_header ==
<include wikitext nopre src="http://wiki.nginx.org/nginx.org/ngx_http_headers_module/add_header.txt" />
+
<include wikitext nopre src="http://wiki.nginx.org/nginx.org/http/ngx_http_headers_module/add_header.txt" />
  
 
Adds headers to the HTTP response when the response code is equal to 200, 204, 301, 302 or 304.  
 
Adds headers to the HTTP response when the response code is equal to 200, 204, 301, 302 or 304.  
Line 23: Line 23:
  
 
== expires ==
 
== expires ==
<include wikitext nopre src="http://wiki.nginx.org/nginx.org/ngx_http_headers_module/expires.txt" />
+
<include wikitext nopre src="http://wiki.nginx.org/nginx.org/http/ngx_http_headers_module/expires.txt" />
  
 
Controls whether the response should be marked with an expiry time, and if so, what [[ConfigurationSyntax|time]] that is.
 
Controls whether the response should be marked with an expiry time, and if so, what [[ConfigurationSyntax|time]] that is.

Revision as of 19:31, 2 May 2012

Contents

Synopsis

This module allows setting arbitrary HTTP headers.

Examples

  expires       24h;
  expires       modified +24h;
  expires       @15h30m;
  expires       0;
  expires       -1;
  expires       epoch;
  add_header    Cache-Control  private;

Directives

add_header

Syntax: add_header name value
Default:
Context: http
server
location
if in location
Reference:add_header


Adds headers to the HTTP response when the response code is equal to 200, 204, 301, 302 or 304.

Note that for headers other than Last-Modified, it just appends a new header entry to the output header list. So you can't use this directive to rewrite existing headers like Server. Use the headers_more module for it.

expires

Syntax: expires [ modified ] time
expires epoch | max | off
Default: off
Context: http
server
location
if in location
Reference:expires


Controls whether the response should be marked with an expiry time, and if so, what time that is.

  • off prevents changes to the Expires and Cache-Control headers.
  • epoch sets the Expires header to 1 January, 1970 00:00:01 GMT.
  • max sets the Expires header to 31 December 2037 23:59:59 GMT, and the Cache-Control max-age to 10 years.
  • A time without an @ prefix specifies an expiry time relative to either the response time (if the time is not preceded with "modified") or the file's modification time (when "modified" is present — available from versions 0.7.0 & 0.6.32). A negative time can be specified, which sets the Cache-Control header to no-cache.
  • Times written with an @ prefix represent an absolute time-of-day expiry, written in either the form Hh or Hh:Mm, where H ranges from 0 to 24, and M ranges from 0 to 59 (available from versions 0.7.9 & 0.6.34).

A non-negative time or time-of-day sets the Cache-Control header to max-age = #, where # is the appropriate time in seconds.


Note: expires works only for 200, 204, 301, 302, and 304 responses.

References

Original Documentation

See Also

  • The third-party headers_more module for adding, replacing, and clearing both input and output headers.