ERR_CONTENT_LENGTH_MISMATCH on nginx and proxy on Chrome when loading large files

妖精的绣舞 提交于 2020-02-12 07:28:40

问题


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/"

回答1:


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




回答2:


I tried all of the above and still couldn't get it to work. Even after resorting to chmod 777. The only thing that solved it for me was to disable caching entirely:

proxy_max_temp_file_size 0;

Whilst not a fix and no good for production use this was OK for me since I'm only using nginx as part of a local development setup.




回答3:


Adding the following line to the nginx config was the only thing that fixed the net::ERR_CONTENT_LENGTH_MISMATCH error for me:

proxy_buffering off;



回答4:


For me the remedy were these two settings:

In the file: /etc/nginx/nginx.conf

Add:

proxy_max_temp_file_size 0;
proxy_buffering off;

Between the lines client_max_body_size 128M; and server_names_hash_bucket_size 256;:

http {

client_max_body_size 128M;
proxy_max_temp_file_size 0;
proxy_buffering off;
server_names_hash_bucket_size 256;



回答5:


ps aux | grep "nginx: worker process"

after executing above command you'll see the user through which nginx is running

eg.

www-data 25356  0.0  0.0  68576  4800 ?        S    12:45   0:00 nginx: worker process

www-data 25357  0.0  0.0  68912  5060 ?        S    12:45   0:00 nginx: worker process

now you have to run below command to give permission

chown -R www-data:www-data /var/lib/nginx/

Hope it will work




回答6:


For us, it turned out to be that our server's rather small root (ie. /) was full.

It had mountains of logs and files from users in /home. Moving all that cruft out to another mounted drive solved things.

Just wanted to share as this can be another cause of the problem.




回答7:


What worked for me was to change the proxy_temp_path to a folder with read/write permissions (777)

location / {
    proxy_temp_path /data/tmp;
}



回答8:


I had same issue. Increasing the space of Directory or Folder where nginx is installed, solved the issue.




回答9:


When I tried the aforementioned solution it didn't fix the issue. I also changed the permission to write on the location but it didn't work. Then I realized I did something wrong in there. In the location to store the file, I had something like

"/storage" + fileName + ".csv"

. I was testing on the Windows environment and it was working great. But later when we moved the application to the Linux environment it stopped working. So later I had to change it to

"./storage" + fileName + ".csv"

and it started working normally.




回答10:


For me, the solution was:

sudo chown -R nginx:nginx /var/cache/nginx/fastcgi_temp/



回答11:


If somebody ran nginx as a different user in the past, ownership of cache folder may be twisted. I got

/var/cache/nginx# LANG=C ls -l proxy_temp/
total 40
drwx------ 18 nginx nginx 4096 Jul 14  2016 0
drwx------ 19 nginx nginx 4096 Jul 14  2016 1
drwx------ 19 nginx nginx 4096 Jul 14  2016 2
drwx------ 19 nginx nginx 4096 Jul 14  2016 3
drwx------ 19 nginx nginx 4096 Jul 14  2016 4
drwx------ 19 nginx nginx 4096 Jul 14  2016 5
drwx------ 19 nginx nginx 4096 Jul 14  2016 6
drwx------ 18 nginx nginx 4096 Jul 14  2016 7
drwx------ 18 nginx nginx 4096 Jul 14  2016 8
drwx------ 18 nginx nginx 4096 Jul 14  2016 9

while nginx was running as www-data. So the solution is to change ownership of nginx’s cache directory to the user nginx is running under. In the present case

/var/cache/nginx# chown -R www-data:www-data *

or, even simpler

# rm -r /var/cache/nginx/*


来源:https://stackoverflow.com/questions/25993826/err-content-length-mismatch-on-nginx-and-proxy-on-chrome-when-loading-large-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!