Path: blob/main/xml/en/docs/http/ngx_http_headers_module.xml
1 views
<?xml version="1.0"?>12<!--3Copyright (C) Igor Sysoev4Copyright (C) Nginx, Inc.5-->67<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">89<module name="Module ngx_http_headers_module"10link="/en/docs/http/ngx_http_headers_module.html"11lang="en"12rev="14">1314<section id="summary">1516<para>17The <literal>ngx_http_headers_module</literal> module allows adding18the <header>Expires</header> and <header>Cache-Control</header> header19fields, and arbitrary fields, to a response header.20</para>2122</section>232425<section id="example" name="Example Configuration">2627<para>28<example>29expires 24h;30expires modified +24h;31expires @24h;32expires 0;33expires -1;34expires epoch;35expires $expires;36add_header Cache-Control private;37</example>38</para>3940</section>414243<section id="directives" name="Directives">4445<directive name="add_header">46<syntax>47<value>name</value> <value>value</value>48[<literal>always</literal>]</syntax>49<default/>50<context>http</context>51<context>server</context>52<context>location</context>53<context>if in location</context>5455<para>56Adds the specified field to a response header provided that57the response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304,58307 (1.1.16, 1.0.13), or 308 (1.13.0).59Parameter value can contain variables.60</para>6162<para id="add_header_default_inherit">63There could be several <literal>add_header</literal> directives.64These directives are inherited from the previous configuration level65if and only if there are no <literal>add_header</literal> directives66defined on the current level.67Inheritance rules can be redefined with the68<link id="add_header_inherit"/> directive (1.29.3).69</para>7071<para>72If the <literal>always</literal> parameter is specified (1.7.5),73the header field will be added regardless of the response code.74</para>7576</directive>777879<directive name="add_header_inherit">80<syntax>81<literal>on</literal> |82<literal>off</literal> |83<literal>merge</literal></syntax>84<default>on</default>85<context>http</context>86<context>server</context>87<context>location</context>88<context>if in location</context>89<appeared-in>1.29.3</appeared-in>9091<para>92Allows altering inheritance rules for the values specified in the93<link id="add_header"/> directives.94By default, the95<link id="add_header_default_inherit">standard</link> inheritance model is used.96</para>9798<para>99The <literal>merge</literal> parameter enables appending values100from the previous level to the values defined at the current level.101</para>102103<para>104The <literal>off</literal> parameter cancels inheritance of the values105from the previous configuration level.106</para>107108<para>109The inheritance rules themselves are inherited in a standard way.110For example, <literal>add_header_inherit merge;</literal>111specified at the top level will112be inherited in all nested levels recursively unless redefined later.113</para>114115</directive>116117118<directive name="add_trailer">119<syntax>120<value>name</value> <value>value</value>121[<literal>always</literal>]</syntax>122<default/>123<context>http</context>124<context>server</context>125<context>location</context>126<context>if in location</context>127<appeared-in>1.13.2</appeared-in>128129<para>130Adds the specified field to the end of a response provided that131the response code equals 200, 201, 206, 301, 302, 303, 307, or 308.132Parameter value can contain variables.133</para>134135<para id="add_trailer_default_inherit">136There could be several <literal>add_trailer</literal> directives.137These directives are inherited from the previous configuration level138if and only if there are no <literal>add_trailer</literal> directives139defined on the current level.140Inheritance rules can be redefined with the141<link id="add_trailer_inherit"/> directive (1.29.3).142</para>143144<para>145If the <literal>always</literal> parameter is specified146the specified field will be added regardless of the response code.147</para>148149</directive>150151152<directive name="add_trailer_inherit">153<syntax>154<literal>on</literal> |155<literal>off</literal> |156<literal>merge</literal></syntax>157<default>on</default>158<context>http</context>159<context>server</context>160<context>location</context>161<context>if in location</context>162<appeared-in>1.29.3</appeared-in>163164<para>165Allows altering inheritance rules for the values specified in the166<link id="add_trailer"/> directives.167By default, the168<link id="add_trailer_default_inherit">standard</link> inheritance model is used.169</para>170171<para>172The <literal>merge</literal> parameter enables appending values173from the previous level to the values defined at the current level.174</para>175176<para>177The <literal>off</literal> parameter cancels inheritance of the values178from the previous configuration level.179</para>180181<para>182The inheritance rules themselves are inherited in a standard way.183For example, <literal>add_trailer_inherit merge;</literal>184specified at the top level will185be inherited in all nested levels recursively unless redefined later.186</para>187188</directive>189190191<directive name="expires">192<syntax>[<literal>modified</literal>] <value>time</value></syntax>193<syntax>194<literal>epoch</literal> |195<literal>max</literal> |196<literal>off</literal></syntax>197<default>off</default>198<context>http</context>199<context>server</context>200<context>location</context>201<context>if in location</context>202203<para>204Enables or disables adding or modifying the <header>Expires</header>205and <header>Cache-Control</header> response header fields provided that206the response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304,207307 (1.1.16, 1.0.13), or 308 (1.13.0).208The parameter can be a positive or negative209<link doc="../syntax.xml">time</link>.210</para>211212<para>213The time in the <header>Expires</header> field is computed as a sum of the214current time and <value>time</value> specified in the directive.215If the <literal>modified</literal> parameter is used (0.7.0, 0.6.32)216then the time is computed as a sum of the file’s modification time and217the <value>time</value> specified in the directive.218</para>219220<para>221In addition, it is possible to specify a time of day using222the “<literal>@</literal>” prefix (0.7.9, 0.6.34):223<example>224expires @15h30m;225</example>226</para>227228<para>229The contents of the <header>Cache-Control</header> field depends230on the sign of the specified time:231<list type="bullet">232233<listitem>234time is negative — <header>Cache-Control: no-cache</header>.235</listitem>236237<listitem>238time is positive or zero —239<header>Cache-Control: max-age=<value>t</value></header>,240where <value>t</value> is a time specified in the directive, in seconds.241</listitem>242243</list>244</para>245246<para>247The <literal>epoch</literal> parameter sets <header>Expires</header>248to the value “<literal>Thu, 01 Jan 1970 00:00:01 GMT</literal>”,249and <header>Cache-Control</header> to “<literal>no-cache</literal>”.250</para>251252<para>253The <literal>max</literal> parameter sets <header>Expires</header>254to the value “<literal>Thu, 31 Dec 2037 23:55:55 GMT</literal>”,255and <header>Cache-Control</header> to 10 years.256</para>257258<para>259The <literal>off</literal> parameter disables adding or modifying the260<header>Expires</header> and <header>Cache-Control</header> response261header fields.262</para>263264<para>265The last parameter value can contain variables (1.7.9):266<example>267map $sent_http_content_type $expires {268default off;269application/pdf 42d;270~image/ max;271}272273expires $expires;274</example>275</para>276277</directive>278279</section>280281</module>282283284