Content-length Missing when response proxy_pass a special backend

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

First backend: kwfs
[email protected]:~$ curl -X GET -I
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
[email protected]:~$ curl -X GET -I
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
[email protected]:~$ curl -X GET -I
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
yangqing[email protected]:~$ curl -X GET -I
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 :slight_smile:

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:
http://forum.nginx.org/read.php?2,216427,216427#msg-216427

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 :slight_smile:

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.

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:
http://forum.nginx.org/read.php?2,216427,216449#msg-216449

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs