Opened 3 years ago

Closed 3 years ago

#2164 closed defect (worksforme)

Unable to add `$upstream_addr` to a response header field

Reported by: michalrus@… Owned by:
Priority: minor Milestone:
Component: nginx-module Version: 1.15.x
Keywords: ngx_http_headers_module Cc:
uname -a: Linux localhost 4.15.0-122-generic #124-Ubuntu SMP Thu Oct 15 13:03:05 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: openresty/1.15.8.1
built with OpenSSL 1.1.0h 27 Mar 2018 (running with OpenSSL 1.1.0k 28 May 2019)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl/include' --add-module=../ngx_devel_kit-0.3.1rc1 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.15 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../ngx_stream_lua-0.0.7 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl/lib' --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-dtrace-probes --with-stream --with-stream_ssl_preread_module --with-http_ssl_module

Description

Whenever $upstream_addr is added to any header field with add_header, that field is missing from responses:

    location {
      proxy_pass http://some_upstream;

      # This works (so request phase should be fine?):

      add_header  X-Upstream-Content-Type $upstream_http_content_type;

      # This doesn’t:

      add_header     X-Upstream-Addr $upstream_addr;    
    }

How can this be achieved?

Thank you!

Change History (2)

comment:1 by Maxim Dounin, 3 years ago

Works fine here, including the long obsolete 1.15.8 version of nginx. Test configuration:

server {
    listen 8080;

    location / {
        proxy_pass http://localhost:8081;
        add_header X-Upstream-Addr $upstream_addr;
    }
}

server {
    listen 8081;
    return 200 ok;
}

Testing with curl:

$ curl -I http://127.0.0.1:8080/
HTTP/1.1 200 OK
Server: nginx/1.15.8
Date: Mon, 19 Apr 2021 14:21:05 GMT
Content-Type: text/plain
Content-Length: 2
Connection: keep-alive
X-Upstream-Addr: 127.0.0.1:8081

Please test if you are able to reproduce the problem with vanilla nginx, not a modified fork you are using. If you are able to, please provide additional details, such as full configuration you are using, and test output which demonstrates that the header is not added.

comment:2 by Maxim Dounin, 3 years ago

Resolution: worksforme
Status: newclosed

Feedback timeout.

Note: See TracTickets for help on using tickets.