GZIP problem with backend hosts

Igor Sysoev is at rambler-co.ru
Fri Aug 29 15:27:07 MSD 2008

On Fri, Aug 29, 2008 at 12:08:21PM +0100, Alan Williamson wrote:

> >If you did not set
> >   proxy_set_header  Accept-Encoding  "";
> >
> >then nginx will pass it backend.
> i do not understand this.  Are you suggesting i need to set this in 
> order for nginx to send that header to the back end?

No, if you set this then nginx will never pass Accept-Encoding to backend.

> What about the other headers that get sent with the request (cookie etc) 
> we don't manually set them do we?  They simply get passed to the backend.

By default all headers goes to backend as is.
There are two exceptions:

1) Host: nginx sets it to $proxy_host value,
2) Connection: nginx sets it "close"

> It always bothers me that nginx doesn't pass "Host:" one and i have to 
> set this manually,  makes me wonder what other headers nginx is silently 
> rejecting and not passing on to the backend.

nginx always sends Host. However, it sets to a value that backend usually
expects to get. In this configuration:

     server {
         server_name  ONE;
         location / {
             proxy_pass http://TWO;

the TWO server usually expects to get "Host: TWO", but not "Host: ONE"
as the ONE server expects. If your TWO server requires "Host: ONE",
then you have to add manually

     proxy_set_header Host $host;
     proxy_set_header Host ONE;

> can you tell me what the definitive answer is here?
> ------ snippet -------
>    location / {
>     proxy_redirect     off;
>     proxy_set_header Host $host;
>     proxy_set_header x-forwarded-for $remote_addr;
>     proxy_pass http://backends;
>    }
> -----------------------

Try to remove 

     proxy_set_header x-forwarded-for $remote_addr;

This may be treated as proxied request on backend side.

> So if a client sends in the header that he can accept GZIP encoding, 
> nginx is removing this and not passing it through.
> So how can i add it back in, but for only the clients that can accept 
> it; a bit silly to ALWAYS add it in especially if its not been set.

As I have said before nginx does not remove "Accept-Enconding" by default.

> >I do not know conditions when Amazon may refuse to compresses response,
> >it may have simillar limits as nginx has:
> this has ***nothing*** to do with Amazon.  I merely was illustrating 
> that our infastructure runs within the EC2 cloud.

As I understand EC2 cloud are Amazon servers. Are your backends EC2 servers ?

Igor Sysoev

More information about the nginx mailing list