加载大文件时,Chrome上的nginx和代理服务器上的ERR_CONTENT_LENGTH_MISMATCH [英] ERR_CONTENT_LENGTH_MISMATCH on nginx and proxy on Chrome when loading large files

查看:2557
本文介绍了加载大文件时,Chrome上的nginx和代理服务器上的ERR_CONTENT_LENGTH_MISMATCH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  GET http:// localhost / grunt / vendor / angular / angular.js net :: ERR_CONTENT_LENGTH_MISMATCH 

只有当同时发生的请求朝向nginx时才会发生,例如当浏览器缓存为空并且整个应用程序加载时。



以下是从Chrome浏览器复制的这些请求的标题:

 远程地址:127.0.0.1:80 
请求URL:http://localhost/grunt/vendor/angular/angular.js
请求方法:GET
状态码:200 OK
请求Headers查看源
接受:* / *
接受编码:gzip,deflate,sdch
Accept-Language:zh-CN,en ; q = 0.8,de; q = 0.6,pl; q = 0.4,es; q = 0.2,he; q = 0.2,gl; q = 0.2
Cache-Control:no-cache
连接:keep-alive
Cookie:gs_u_GSN-265185-D = 1783247335:2567:5000:1377697930719
Host:localhost
Pragma:no-cache
Referer:http:// localhost / grunt /
用户代理:Mozilla / 5.0(Macintosh; Intel Mac OS X 10_9_4)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 37.0.2062.122 Safari / 537.36
响应Headersview源
Accept-Ranges:bytes
Cache-Control:public,max-age = 0
连接:keep-alive
Content-Length:873444
Content-Type:application / javascript
日期:2014年9月23日星期二11:08:19 GMT
ETag:873444-1411465226000
上次修改时间:2014年9月23日星期二09:40:26 GMT
服务器: nginx / 1.6.0

文件的真实大小:

  $ ll vendor / angular / angular.js 
-rw-rw-r-- 1 xxxx staff 873444 Aug 30 07:21 vendor / angular / angular .js

您可以看到 Content-Length 和文件的实际大小是一样的,所以这很奇怪。



以及此代理的nginx配置:

  location / grunt / {
proxy_pass http:// localhost:9000 /;

$ / code>

任何想法?

感谢

编辑:在错误日志中找到更多信息:

  2014/09/23 13:08:19 [crit] 15435#0:* 8 open()/ usr / local / var / run / nginx / proxy_temp / 1/00/0000000001失败(13:Permission denied )在读取上游时,客户端:127.0.0.1,server:localhost,请求:GET /grunt/vendor/angular/angular.js HTTP / 1.1,上游:http://127.0.0.1:9000/vendor/angular /angular.js,host:localhost,referrer:http:// localhost / grunt /


angular.js 并且不能由于权限问题。下面是解决这个问题的方法:

$ $ $ $ $ $ $ $ $ c $ root $ amac-2 / usr / local / var / run / nginx $ chown -R _www:admin proxy_temp

_www:admin might在你的情况下不同,取决于哪个用户拥有nginx进程。查看更多有关ServerFault的信息:



https://serverfault.com/questions/534497/why-do-nginx-process-run-with-user-nobody

I'm getting the following error on my chrome console:

GET http://localhost/grunt/vendor/angular/angular.js net::ERR_CONTENT_LENGTH_MISMATCH 

This only happens when a simultaneous requests are shot towards nginx e.g. when the browsers cache is empty and the whole app loads. Loading the resource above as a single requests succeeds.

Here are the headers to this requests, copied from Chrome:

Remote Address:127.0.0.1:80
Request URL:http://localhost/grunt/vendor/angular/angular.js
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,de;q=0.6,pl;q=0.4,es;q=0.2,he;q=0.2,gl;q=0.2
Cache-Control:no-cache
Connection:keep-alive
Cookie:gs_u_GSN-265185-D=1783247335:2567:5000:1377697930719
Host:localhost
Pragma:no-cache
Referer:http://localhost/grunt/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.122 Safari/537.36
Response Headersview source
Accept-Ranges:bytes
Cache-Control:public, max-age=0
Connection:keep-alive
Content-Length:873444
Content-Type:application/javascript
Date:Tue, 23 Sep 2014 11:08:19 GMT
ETag:"873444-1411465226000"
Last-Modified:Tue, 23 Sep 2014 09:40:26 GMT
Server:nginx/1.6.0

the real size of the file:

$ ll vendor/angular/angular.js
-rw-rw-r--  1 xxxx  staff  873444 Aug 30 07:21 vendor/angular/angular.js

As you can see Content-Length and the real size of the file are the same, so that's weird

And the nginx configuration to this proxy:

location /grunt/ {
    proxy_pass  http://localhost:9000/;
}

Any ideas?

Thanks

EDIT: found more info on the error log:

2014/09/23 13:08:19 [crit] 15435#0: *8 open() "/usr/local/var/run/nginx/proxy_temp/1/00/0000000001" failed (13: Permission denied) while reading upstream, client: 127.0.0.1, server: localhost, request: "GET /grunt/vendor/angular/angular.js HTTP/1.1", upstream: "http://127.0.0.1:9000/vendor/angular/angular.js", host: "localhost", referrer: "http://localhost/grunt/"

解决方案

It seems that under pressure, nginx tried to pull angular.js from its cache and couldn't due to permission issues. Here's what solved this issue:

root@amac-2:/usr/local/var/run/nginx $ chown -R _www:admin proxy_temp

_www:admin might be different in your case, depending which user owns the nginx process. See more information on ServerFault:

https://serverfault.com/questions/534497/why-do-nginx-process-run-with-user-nobody

这篇关于加载大文件时,Chrome上的nginx和代理服务器上的ERR_CONTENT_LENGTH_MISMATCH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆