Opened 9 months ago

Closed 9 months ago

#2543 closed defect (invalid)

wrong "host" header when using upstreams

Reported by:… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.24.x
Keywords: Cc:
uname -a: Linux reverse-proxy-nginx-69666dccb-mbnfn 5.15.128-1-MANJARO #1 SMP PREEMPT Sat Aug 26 17:22:47 UTC 2023 x86_64 GNU/Linux
nginx -V: $ nginx -V
nginx version: nginx/1.24.0
built with OpenSSL 1.1.1n 15 Mar 2022
TLS SNI support enabled
configure arguments: --prefix=/opt/bitnami/nginx --with-http_stub_status_module --with-stream --with-http_gzip_static_module --with-mail --with-http_realip_module --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-mail_ssl_module --with-http_gunzip_module --with-threads --with-http_auth_request_module --with-http_sub_module --with-http_geoip_module --with-compat --with-stream_realip_module --with-stream_ssl_module --with-cc-opt=-Wno-stringop-overread --add-module=/bitnami/blacksmith-sandox/nginx-module-vts-0.2.2 --add-dynamic-module=/bitnami/blacksmith-sandox/nginx-module-geoip2-3.4.0 --add-module=/bitnami/blacksmith-sandox/nginx-module-substitutions-filter-0.20220124.0 --add-dynamic-module=/bitnami/blacksmith-sandox/nginx-module-brotli-0.20220429.0

Description (last modified by…)


we have a reverse proxy setup with 2 upstreams, the decision to which upstream to route a request is based on value of a specific header.
Lets say we want to route requests to upstreams based on a value of the user-agent header

          upstream banana {
             server banana-server;
           upstream apple {
             server apple-server;

          map $http_user_agent $proxied_server {
            default apple;

            "~*Firefox*" apple;
            "~*Chrome*" banana;
          server {
              listen 8080;
              server_name localhost;
              location / {
                    proxy_pass http://$proxied_server;

the request is sent to the right upstream IP by a reverse proxy, but instead of taking the DNS name of the server specified in the "upstream" the reverse proxy takes the name of upstream as a value for the host header. So instead of "banana-server" it sends just "banana".

Change History (2)

comment:1 by…, 9 months ago

Description: modified (diff)

comment:2 by Sergey Kandaurov, 9 months ago

Resolution: invalid
Status: newclosed

This is the default behaviour of the proxy_set_header directive.
See for details.

If you have further questions with configuring nginx, please consider using nginx@ mailing list instead.

Note: See TracTickets for help on using tickets.