# Content-length Missing when response proxy\_pass a special backend

**URL:** <https://www.ruby-forum.com/t/content-length-missing-when-response-proxy-pass-a-special-backend/212650>\
**Category:** NGINX\
**Created:** [October 9, 2011, 4:27pm UTC](https://www.ruby-forum.com/t/content-length-missing-when-response-proxy-pass-a-special-backend/212650 "2011-10-09T16:27:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [October 9, 2011, 4:27pm UTC](https://www.ruby-forum.com/t/content-length-missing-when-response-proxy-pass-a-special-backend/212650/1 "2011-10-09T16:27:07Z")

</div>

I have 2 backends in my applications.There are pure backend response  
example:

First backend: kwfs  
yangqingchang@yqc:~$ curl -X GET -I  
[http://192.168.1.118:8080/kwfs/AAChTwAAADcAAwAc](http://192.168.1.118:8080/kwfs/AAChTwAAADcAAwAc)  
HTTP/1.1 200 OK  
Server: QWS/1.0  
Content-Type: application/octet-stream  
Connection: keep-alive  
Cache-Control: max-age=604800  
Date: Sun, 09 Oct 2011 13:35:57 GMT  
Content-Length: 1239

Second backend: account  
yangqingchang@yqc:~$ curl -X GET -I  
[http://192.168.60.99:18000/account/visualconfirm/?page=register](http://192.168.60.99:18000/account/visualconfirm/?page=register)  
HTTP/1.1 200 OK  
Content-Length: 1044  
Etag: “f91a3c56177d3edf13a96e0772410d23b531cef5”  
Content-Type: image/jpeg  
Server: TornadoServer/1.0

After kwfs response across nginx, “Transfer-Encoding: chunked” appeared  
in it’s headers , and “Content-Length” was replaced.

First proxy: kwfs  
yangqingchang@yqc:~$ curl -X GET -I  
[http://192.168.60.96:8000/kwfs/AAChTwAAADcAAwAC](http://192.168.60.96:8000/kwfs/AAChTwAAADcAAwAC)  
HTTP/1.1 200 OK  
Date: Sun, 09 Oct 2011 13:58:07 GMT  
Content-Type: application/octet-stream  
Transfer-Encoding: chunked  
Connection: keep-alive  
Server: QWS/1.0  
Cache-Control: max-age=604800

Second proxy: account  
yangqingchang@yqc:~$ curl -X GET -I  
[http://192.168.60.96:8000/account/visualconfirm/?page=register](http://192.168.60.96:8000/account/visualconfirm/?page=register)  
HTTP/1.1 200 OK  
Date: Sun, 09 Oct 2011 13:59:07 GMT  
Content-Type: image/jpeg  
Connection: keep-alive  
Content-Length: 1014  
Etag: “bb6c20817a926b5ad761ec7a229f0f6d20adf1cb”  
Server: TornadoServer/1.0

I need the “Content-Length” for calculating the downloading process in  
client.  
But I really don’t know with same config, why “Content-length” missing  
when a special response proxy\_pass by nginx, and another is ok.  
Could anybody tell me why? Thanks a lot 🙂

My config:

server {  
listen 192.168.60.96:8000;  
client\_max\_body\_size 2M;

```
location /kwfs {
    proxy_redirect off;
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://192.168.1.118:8080;
}

location /account {
    proxy_redirect off;
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://192.168.60.99:18000;
}

```

}

My nginx :  
nginx -V  
nginx version: nginx/0.7.65  
built by gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5)  
TLS SNI support enabled  
configure arguments: --prefix=/usr/local/nginx-0.7.65  
–with-http\_stub\_status\_module --with-http\_gzip\_static\_module  
–with-http\_ssl\_module --with-http\_realip\_module  
–with-openssl=/home/yangqingchang/Downloads/openssl-0.9.8l  
–with-pcre=/home/yangqingchang/Downloads/pcre-8.01  
–add-module=/home/yangqingchang/Downloads/nginx\_upload\_module-2.0.12

Posted at Nginx Forum:

> **[Content-length Missing when response proxy\_pass a special backend](https://forum.nginx.org/read.php?2,216427,216427#msg-216427)**
>
> I have 2 backends in my applications.There are pure backend response example: First backend: kwfs yangqingchang@yqc:~$ curl -X GET -I http://192.168.1.118:8080/kwfs/AAChTwAAADcAAwAc HTTP/1.1 200 OK Server: QWS/1.0 Content-Type:...

---

<div class="post-metadata">

**Author:** ![fzuslide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/53a042/32.png) [@fzuslide](https://www.ruby-forum.com/u/fzuslide)\
**Post date:** [October 9, 2011, 10:56pm UTC](https://www.ruby-forum.com/t/content-length-missing-when-response-proxy-pass-a-special-backend/212650/2 "2011-10-09T22:56:08Z")

</div>

Hello!

On Sun, Oct 09, 2011 at 10:26:37AM -0400, fzuslide wrote:

[…]

> Content-Type: application/octet-stream  
> Transfer-Encoding: chunked

[…]

> Content-Type: image/jpeg  
> Connection: keep-alive  
> Content-Length: 1014

[…]

> I need the “Content-Length” for calculating the downloading process in  
> client.  
> But I really don’t know with same config, why “Content-length” missing  
> when a special response proxy\_pass by nginx, and another is ok.  
> Could anybody tell me why? Thanks a lot 🙂

nginx removes Content-Length header (and uses chunked if possible)  
if resulting length after processing isn’t known. This happens  
e.g. if you use gzip, ssi, sub or addition modules.

> My config:
> 
> server {  
> listen 192.168.60.96:8000;

[…]

> }

You have to provide full config (i.e. what’s on http level?).  
Best guess without seeing your config is that you have ssi or  
something similar enabled for “application/octet-stream”, but not  
for “image/jpeg”.

Maxim D.

---

<div class="post-metadata">

**Author:** ![fzuslide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/53a042/32.png) [@fzuslide](https://www.ruby-forum.com/u/fzuslide)\
**Post date:** [October 10, 2011, 6:04am UTC](https://www.ruby-forum.com/t/content-length-missing-when-response-proxy-pass-a-special-backend/212650/3 "2011-10-10T06:04:19Z")

</div>

Hi, Maxim,  
Thanks for your replies.  
I got the reason when my partner check his code.  
Trouble shooting:  
If the backend did not set “Content-Length” or “Chunked” in  
headers , nginx will use chunked as default, but curl and firefox will  
use “Content-Length” as default. This makes me lose direction for the  
problem, lol.  
So if backend set “Content-Length” in his response headers,  
everything is ok!

```
  Btw, If I want use gzip for downloading, is there any method

```

support use “Content-Length” ? I look up GzipStaticModule document,  
there is not introduction for this.  
With kind Regards!

fzuslide

Posted at Nginx Forum:

> **[Re: Content-length Missing when response proxy\_pass a special backend](https://forum.nginx.org/read.php?2,216427,216449#msg-216449)**
>
> I have 2 backends in my applications.There are pure backend response example: First backend: kwfs yangqingchang@yqc:~$ curl -X GET -I http://192.168.1.118:8080/kwfs/AAChTwAAADcAAwAc HTTP/1.1 200 OK Server: QWS/1.0 Content-Type:...
