Dunstkreis
Dunstkreis

Reputation: 104

set not add header in nginx

Is there a way to set / replace / merge a header in nginx like its possible in apache?

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. This brings up some problems, if the header has already been set (e.g. through the php code) and should be replaced / changed to correct values.

For apache one can set / append / merge and add, 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.

Upvotes: 0

Views: 2731

Answers (2)

Thomas Balsløv
Thomas Balsløv

Reputation: 57

Actually the Nginx "add_header" directive will not overwrite the header but add the value to it if it exists. It is not so clear from the docs however: 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."

Upvotes: 1

Tan Hong Tat
Tan Hong Tat

Reputation: 6879

Take a look at 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.

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.

Source: http://wiki.nginx.org/HttpHeadersMoreModule

Upvotes: 2

Related Questions