我在我的铬控制台上得到了以下错误:
GET http://localhost/grunt/vendor/angular/angular.js net::ERR_CONTENT_LENGTH_MISMATCH
这只有在同时向nginx发出请求时才会发生,例如,当浏览器缓存为空并且整个应用程序加载时。在单个请求成功的情况下加载上述资源。
以下是从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
文件的实际大小:
$ 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/;
}
有什么想法吗?
谢谢
编辑:找到关于错误日志的更多信息:
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/"
发布于 2014-09-23 11:34:19
看来,在压力下,nginx试图从缓存中提取angular.js
,但由于权限问题,无法做到这一点。以下是解决这个问题的方法:
root@amac-2:/usr/local/var/run/nginx $ chown -R _www:admin proxy_temp
在您的情况下,_www:admin
可能是不同的,这取决于哪个用户拥有nginx进程。请参阅有关ServerFault的更多信息:
https://serverfault.com/questions/534497/why-do-nginx-process-run-with-user-nobody
发布于 2017-12-23 23:57:00
将以下行添加到nginx是唯一为我修复net::ERR_CONTENT_LENGTH_MISMATCH
错误的地方:
proxy_buffering off;
发布于 2016-06-30 09:00:39
我试过以上所有的方法,但仍然无法让它发挥作用。即使在求助于chmod 777
之后。唯一解决这个问题的方法是完全禁用缓存:
proxy_max_temp_file_size 0;
虽然这不是一个修复,也不利于生产使用,但这对我来说还可以,因为我只使用nginx作为本地开发设置的一部分。
https://stackoverflow.com/questions/25993826
复制相似问题