简体   繁体   English

在nginx中设置不添加标题

[英]set not add header in nginx

Is there a way to set / replace / merge a header in nginx like its possible in apache? 有没有办法像在Apache中那样设置/替换/合并nginx中的标头?

regarding to this link http://nginx.org/en/docs/http/ngx_http_headers_module.html it seems, that its only possible to add a header. 关于此链接http://nginx.org/zh-CN/docs/http/ngx_http_headers_module.html看来,只能添加标头。 This brings up some problems, if the header has already been set (eg through the php code) and should be replaced / changed to correct values. 如果已经设置了标头(例如通过php代码),并且应该将其替换/更改为正确的值,则会带来一些问题。

For apache one can set / append / merge and add, http://httpd.apache.org/docs/2.2/mod/mod_headers.html 对于apache来说,可以设置/附加/合并和添加, http://httpd.apache.org/docs/2.2/mod/mod_headers.html

this is kinda basic feature, so it should be possible in nginx somehow, but i cant find out. 这是一个基本功能,因此应该可以在Nginx中实现,但是我找不到。

Take a look at HttpHeadersMoreModule. 看看HttpHeadersMoreModule。

This module allows you to add, set, or clear any output or input header that you specify. 该模块允许您添加,设置或清除您指定的任何输出或输入标头。

This is an enhanced version of the standard headers module because it provides more utilities like resetting or clearing "builtin headers" like Content-Type, Content-Length, and Server. 这是标准标头模块的增强版本,因为它提供了更多实用程序,如重置或清除“内置标头”,如Content-Type,Content-Length和Server。

It also allows you to specify an optional HTTP status code criteria using the -s option and an optional content type criteria using the -t option while modifying the output headers with the more_set_headers and more_clear_headers directives. 它还允许您使用-s选项指定可选的HTTP状态代码条件,并使用-t选项指定可选的内容类型条件,同时使用more_set_headers和more_clear_headers指令修改输出标头。

Source: http://wiki.nginx.org/HttpHeadersMoreModule 资料来源: http : //wiki.nginx.org/HttpHeadersMoreModule

Actually the Nginx "add_header" directive will not overwrite the header but add the value to it if it exists. 实际上,Nginx的“ add_header”指令不会覆盖标头,而是将其添加到该标头(如果存在)。 It is not so clear from the docs however: http://nginx.org/en/docs/http/ngx_http_headers_module.html#add_header 但是从文档中并不清楚: http : //nginx.org/en/docs/http/ngx_http_headers_module.html#add_header

But in the HttpHeadersMoreModule docs ( https://github.com/openresty/headers-more-nginx-module#more_set_headers ) it says: "If you want to add headers incrementally, use the standard add_header directive instead." 但是在HttpHeadersMoreModule文档( https://github.com/openresty/headers-more-nginx-module#more_set_headers )中说:“如果要增量添加标头,请改用标准add_header指令。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM