Preserving all original request headers through a proxy_pass?

I’m probably being a bit lazy here, I have only skimmed the code, but is
there a way to bounce all original request headers through a proxy_pass
prefixed with X-Orig-* or something like that?

One reason for wanting to do this is for proxy detection. Common
headers that are important to preserve are HTTP_X_FORWARDED, HTTP_VIA
and HTTP_PROXY_CONNECTION.

-R

Hi,

On 07/12/2010 01:25, Rasmus Lerdorf wrote:

I’m probably being a bit lazy here, I have only skimmed the code, but is
there a way to bounce all original request headers through a proxy_pass
prefixed with X-Orig-* or something like that?

One reason for wanting to do this is for proxy detection. Common
headers that are important to preserve are HTTP_X_FORWARDED, HTTP_VIA
and HTTP_PROXY_CONNECTION.
Yes, you can use the proxy_set_header directive
(Module ngx_http_proxy_module).

e.g.

proxy_set_header NAME $value;

You can obviously choose anything for NAME, including X-Orig-…, and
the values can be static strings or generated using variables.

Marcus.

On 12/6/10 3:46 PM, Eugaia wrote:

Yes, you can use the proxy_set_header directive
(Module ngx_http_proxy_module).

e.g.

proxy_set_header NAME $value;

You can obviously choose anything for NAME, including X-Orig-…, and
the values can be static strings or generated using variables.

Well, the key word was “all” in the question. I know I can set
individual ones. I essentially want:

proxy_set_header X-Orig-* $http_*

Since I don’t know what the full set might be.

-Rasmus

Hello!

On Mon, Dec 06, 2010 at 04:15:45PM -0800, Rasmus Lerdorf wrote:

and HTTP_PROXY_CONNECTION.
Well, the key word was “all” in the question. I know I can set
individual ones. I essentially want:

proxy_set_header X-Orig-* $http_*

Since I don’t know what the full set might be.

Short answer:

No.

Long answer:

There is no way to pass all headers prefixed. On the other hand,
nginx passes most of the headers to upstream by default (with
their original names), and the only headers which are mungled by
default are Host, Connection, Keep-Alive, Expect (note that this
list a bit longer when proxy_cache is used, see [1]).

So you actually need to pass only original values of these headers
(plus ones you’ve mangled yourself via proxy_set_header
directive). Or even don’t pass anything special at all as long as
you’ve not mangled headers critical for your task.

[1]
http://mdounin.ru/hg/nginx-vendor-current/file/f6fa6099ee59/src/http/modules/ngx_http_proxy_module.c#l508

Maxim D.

Hello!

On Thu, Dec 30, 2010 at 04:56:00PM -0500, elgreco wrote:

I dont know if i can ask in the same topic my question…

General rule is: don’t hijack threads.

    server {

  listen 80;
     server_name www.domain.local;
        location / {
          proxy_pass  http://backend;
          proxy_set_header        Host            $host;
        }
}

Most likely you don’t have “www.domain.local” configured as
virtualhost on your backends, and that’s why it doesn’t work.

Maxim D.

I dont know if i can ask in the same topic my question…

i have a upstream of two servers which responds on host headers only
(apache virtualhost’s)
when i try to open the www.server.local (which is nginx frontend) i get
only default web pages from backends and not the web1 or web2
what should i do to fix the problem ?

upstream backend {
                server web1.local.com:80;
                server web2.local.com:80;
        }
        server {

      listen 80;
         server_name www.domain.local;
            location / {
              proxy_pass  http://backend;
              proxy_set_header        Host            $host;
            }
    }

Posted at Nginx Forum:

hi!
You are great!

The problem was that i was missing the right virtualhost ServerName www.domain.local
name in the apache’s conf file.

I was thinking that nginx is sending proxy headers internally using the
server name listed in the upstream server list.

thanks

Posted at Nginx Forum: