# Missing Content-Length in nginx response

**URL:** <https://www.ruby-forum.com/t/missing-content-length-in-nginx-response/205725>\
**Category:** NGINX\
**Created:** [April 14, 2011, 9:51am UTC](https://www.ruby-forum.com/t/missing-content-length-in-nginx-response/205725 "2011-04-14T09:51:09Z")\
**Posts on this page:** 2\
**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:** [April 14, 2011, 9:51am UTC](https://www.ruby-forum.com/t/missing-content-length-in-nginx-response/205725/1 "2011-04-14T09:51:09Z")

</div>

Hello,

I have problems in a transition from Apache to nginx.

There are 2 nginx servers working together:  
nginx (balancing, proxy) → another nginx → static files and php-fpm

Pages that are loaded through ajax doesn’t show up.

I checked through Firebug and the only differences are in following  
response headers

1. Transfer-Encoding chunked (presents only in Nginx response)
2. Content-Length 571 (presents only in Apache response)…

How I can force nginx to work correctly here? Please see full dump of  
headers below.

nginx 0.8.54  
Tried to switch off gzip - it didn’t affect this issue at all.  
ssl is not used in this configuration.  
CentOS 5.5.

I appreciate any information regarding this issue

Best regards,  
Ruslan D.

## Nginx, doesn’t work correctly:

=== Response Headers  
Server nginx  
Date Thu, 14 Apr 2011 07:33:14 GMT  
Content-Type text/html  
Transfer-Encoding chunked  
Connection keep-alive  
X-Powered-By PHP/5.3.6  
Set-Cookie PHPSESSID=790f5bfc9113be4f9ea34a6744aca983; path=/  
ExpiresThu, 19 Nov 1981 08:52:00 GMT  
Cache-Control no-store, no-cache, must-revalidate, post-check=0,  
pre-check=0  
Pragmano-cache  
Content-Encoding gzip

=== Request Headers  
Host \*\*\*\*\*  
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0) Gecko/20100101  
Firefox/4.0  
Accept _/_  
Accept-Languag een-us,ru;q=0.7,en;q=0.3  
Accept-Encoding gzip, deflate  
Accept-Charset ISO-8859-1,utf-8;q=0.7,\*;q=0.7  
Keep-Alive 115  
Connection keep-alive  
Content-Type application/x-www-form-urlencoded  
Referer [http://www](http://www)._**/  
Origin [http://www](http://www).**_

## Another server, Apache:

=== Response Headers  
Date Thu, 14 Apr 2011 07:26:40 GMT  
Server Apache/2  
X-Powered-By PHP/5.2.14  
ExpiresThu, 19 Nov 1981 08:52:00 GMT  
Cache-Control no-store, no-cache, must-revalidate, post-check=0,  
pre-check=0  
Pragma no-cache  
Vary Accept-Encoding,User-Agent  
Content-Encoding gzip  
Content-Length 571  
Keep-Alive timeout=1, max=100  
Connection Keep-Alive  
Content-Type text/html

=== Request Headers  
Host \*\*\*\*\*  
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0) Gecko/20100101  
Firefox/4.0  
Accept\*/\*  
Accept-Language en-us,ru;q=0.7,en;q=0.3  
Accept-Encoding gzip, deflate  
Accept-Charset ISO-8859-1,utf-8;q=0.7,\*;q=0.7  
Keep-Alive115  
Connection keep-alive  
Content-Type application/x-www-form-urlencoded  
X-Requested-With XMLHttpRequest  
Referer http://\*\*\*\*\*/

---

<div class="post-metadata">

**Author:** ![Ruslan\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/48db29/32.png) [@Ruslan\_D](https://www.ruby-forum.com/u/Ruslan_D)\
**Post date:** [April 14, 2011, 12:29pm UTC](https://www.ruby-forum.com/t/missing-content-length-in-nginx-response/205725/2 "2011-04-14T12:29:22Z")

</div>

Hello!

On Thu, Apr 14, 2011 at 01:50:49AM -0600, Ruslan D. wrote:

> response headers
> 
> 1. Transfer-Encoding chunked (presents only in Nginx response)
> 2. Content-Length 571 (presents only in Apache response)…
> 
> How I can force nginx to work correctly here? Please see full dump of  
> headers below.

There is nothing incorrect in returning chunked response as long  
as client uses HTTP/1.1.

I tend to think that your issue is unrelated. You may want to dig  
further into your ajax code to see what actually goes wrong.

> nginx 0.8.54  
> Tried to switch off gzip - it didn’t affect this issue at all.  
> ssl is not used in this configuration.  
> CentOS 5.5.

nginx uses chunked if (a) response length isn’t known (i.e.  
backend doesn’t return it) or (b) it has to modify response body.

The (b) includes gzip filter, ssi filter, sub filter, addition  
filter, and charset filter. With all of them switched off  
(default) you should see original Content-Length from backend’s  
response (if any).

Maxim D.
