Does the nginx support "Header append ..."?

agentzh agentzh at
Tue Mar 1 11:58:53 MSK 2011

On Mon, Feb 28, 2011 at 5:36 PM, sunjipeng_neu <nginx-forum at> wrote:
> But for Nginx, neither "add_header" nor "more_set_headers" directive can
> "append" a value to an exsisting headers.

Yes, ngx_headers_more does not support header appending yet. But it is
a TODO and patches are also welcomed.

> Especially, the "more_set_headers" will create a duplicate headers of
> the same name. i.e.
> Vary: Host
> Vary: User-Agent

I cannot reproduce this with nginx 0.8.54 + ngx_headers_more v0.14.
I'm using the following test case:

    location /foo {
        more_set_headers 'Vary: gbk';
        echo hello;

    location /len {
        default_type 'text/plain';
        more_set_headers 'Vary: hello';

Then we get

    $ curl localhost:1984/len
    HTTP/1.1 200 OK
    Server: nginx/0.8.54 (without pool)
    Date: Tue, 01 Mar 2011 08:52:13 GMT
    Content-Type: text/plain
    Connection: keep-alive
    Content-Length: 6
    Vary: hello


    $ curl localhost:1984/foo
    HTTP/1.1 200 OK
    Server: nginx/0.8.54 (without pool)
    Date: Tue, 01 Mar 2011 08:51:31 GMT
    Content-Type: text/plain
    Transfer-Encoding: chunked
    Connection: keep-alive
    Vary: gbk


Note that accessing /len does not yield duplicate Vary headers. Using
telnet gives exactly the same results.

Could you please provide a minimal sample config that could reproduce
this problem? It's preferable to create a ticket at the GitHub issues
panel though:

> So, What's the reason for it? How should I do for the "append"?

ngx_lua does allow header append, but may not be meaningful in your
context. Here's a small Lua example though:

   ngx.header["Vary"] = ngx.header["Vary"] .. ", UserAgent"

It seems like a good chance to implement the
"output_header_filter_by_lua" directive ;)


More information about the nginx mailing list