0

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.

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I would prefer a build in option, but it seems that its not supported and needs to be installed. So i guess i need to install it, but if i am right i need to keep track manualy if my installed nginx version updates and i need to install the new version of this package? Thank you for the link anyways.
1

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."

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.