nested location + proxy_cache + http/server proxy_hide_header = bug

Maxim Dounin mdounin at mdounin.ru
Tue Jul 24 16:13:49 UTC 2012


Hello!

On Thu, Jul 12, 2012 at 02:19:21PM -0700, Konstantin Svist wrote:

> Запрос на /index.php; бэкенд возвращает X-Powered-By: PHP...
> 
> Конфиг:
> 
>     proxy_hide_header  X-Powered-By; # не работает
>     server  {
>         listen  80;
>         proxy_hide_header X-Powered-By; # не работает
>         location / {
>             proxy_pass  http://localhost:1180;
>             proxy_hide_header X-Powered-By;   # работает
>             location ~ \.php$ {
>                 proxy_hide_header X-Powered-By;   # работает
>                 proxy_cache  mycache;
>                 proxy_set_header  Host   'foobar.com';
>             }
>         }

Патч:

# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1343146145 -14400
# Node ID 964382f88187bb13dab1d21dfc89850be4d45206
# Parent  0f15a7663b9d2ba305d6fb0e304bbd3ce8d32327
Upstream: hide_headers/pass_headers inheritance fix.

Hide headers and pass headers arrays might not be inherited correctly
into a nested location, e.g. in configuration like:

    server {
        proxy_hide_header X-Foo;
        location / {
            location /nested/ {
                proxy_pass_header X-Pad;
            }
        }
    }

Reported by Konstantin Svist,
http://mailman.nginx.org/pipermail/nginx-ru/2012-July/047555.html

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -4541,6 +4541,9 @@ ngx_http_upstream_hide_headers_hash(ngx_
     if (conf->hide_headers == NGX_CONF_UNSET_PTR
         && conf->pass_headers == NGX_CONF_UNSET_PTR)
     {
+        conf->hide_headers = prev->hide_headers;
+        conf->pass_headers = prev->pass_headers;
+
         conf->hide_headers_hash = prev->hide_headers_hash;
 
         if (conf->hide_headers_hash.buckets
@@ -4552,9 +4555,6 @@ ngx_http_upstream_hide_headers_hash(ngx_
             return NGX_OK;
         }
 
-        conf->hide_headers = prev->hide_headers;
-        conf->pass_headers = prev->pass_headers;
-
     } else {
         if (conf->hide_headers == NGX_CONF_UNSET_PTR) {
             conf->hide_headers = prev->hide_headers;


Maxim Dounin



Подробная информация о списке рассылки nginx-ru