Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Implementation of Nginx Operation response header Information

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Precondition: ngx_http_headers_module module needs to be compiled to support header header operation

Add_header

It means to add custom header information to the response header with the instruction add_header name value [always];, which can be used in the context of http {}, server {}, location {}, if in location {}

It takes effect only when the response status code equals 200,2011,204,206,301,302,303,304,307 (1.1.16,1.0.13), or 308 (1.13.0). If the always parameter is specified, the header information will ignore the status code and be forced to return in all responses.

Note: multiple add_header instructions can be declared, and the add_header information declared by the superior will be inherited if and only if the current block does not have add_header.

For example:

Server {add_header a 123; location / {root / path;} location / download/ {add_header b 321;}}

As in the example above, header information such as b 321 will be returned when accessing / download/ routing, and a 123 header information specified by the superior will be returned when accessing / routing.

Add_trailer

It means that the custom header information is added to the end of the response header, and the instruction is add_trailer name value [always]; it can be used in the context of http {}, server {}, location {}, if in location {}. It takes effect only when the response status code equals 200,201,206,301,302303307, or 308. If the always parameter is specified, the header information will ignore the status code and be forced to return in all responses.

Note: multiple add_trailer instructions can be declared, and the add_trailer information declared by the superior will be inherited if and only if the current block does not have add_trailer.

For example, refer to the example of add_header.

Expires

Enable or disable, add or modify the "Expires" and "Cache-Control" fields in the response header, and the instruction is expires [modified] time; or expires epoch | max | off; takes effect when the response status code equals 200,201,204,204,204,204,204,301,302,303,303,307 (1.1.16,1.0.13), or 308 (1.13.0). The time parameter can be a positive time or a negative time. " The time in the "Expires" field is calculated as the sum of the current time and the time specified in the time. If you use this modified parameter (0.7.0d0.6.32), the time is calculated as the sum of the file modification time and the time specified in the time instruction.

In addition, you can specify the time of day using the "@" prefix (0.7.9, 0.6.34): expires @ 15h40m

The content of the "Cache-Control" field depends on the symbol of the specified time:

Time is negative-"Cache-Control: no-cache" time is positive or 0-"Cache-Control: max-age=t" t is the time specified in the instruction, in seconds

The epoch parameter sets "Expires" to the value "Thu, 01 Jan 1970 00:00:01 GMT" and "Cache-Control" to "no-cache".

The max parameter sets "Expires" to the value "Thu, 31 Dec 2037 23:55:55 GMT" and "Cache-Control" to 10 years.

The off parameter disables adding or modifying the "Expires" and "Cache-Control" response header fields.

The last parameter value can contain a variable (1.7.9): for example:

Map $sent_http_content_type $expires {default off; application/pdf 42d; ~ image/ max;} expires $expires

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report