blog icon indicating copy to clipboard operation
blog copied to clipboard

Nginx 做代理时浏览器报错 net::ERR_CONTENT_LENGTH_MISMATCH

Open xhlwill opened this issue 7 years ago • 4 comments

开发时用 nginx 反向代理浏览器报了个错:

net::ERR_CONTENT_LENGTH_MISMATCH

以前也没出现这问题啊,看了下 nginx 配置,没啥问题,再看日志 /usr/local/var/log/nginx/error.log

... "/usr/local/var/run/nginx/proxy_temp/5/00/0000000005" failed (13: Permission denied) ...

应该是对缓存文件的权限问题,搜索找到 http://stackoverflow.com/questions/25993826/err-content-length-mismatch-on-nginx-and-proxy-on-chrome-when-loading-large-file 说问题出在运行 nginx 进程的用户

nobody           13444   0.0  0.0  2464464   1540   ??  S    12:03   0:00.01 nginx: worker process
root             13443   0.0  0.0  2455012    412   ??  Ss   12:03   0:00.00 nginx: master process nginx

和 proxy_temp 文件夹的用户和用户组

drwx------  2 nobody  admin   68  5 11 23:43 client_body_temp
drwx------  2 nobody  admin   68  5 11 23:43 fastcgi_temp
drwx------  2 nobody  admin   68  5 11 23:43 proxy_temp
drwx------  2 nobody  admin   68  5 11 23:43 scgi_temp
drwx------  2 nobody  admin   68  5 11 23:43 uwsgi_temp

答案说 nginx 拿文件时权限不对,更改权限root@amac-2:/usr/local/var/run/nginx $ chown -R _www:admin proxy_temp就行。 按说我的 worker process 的用户是 nobody,proxy_temp 用户也是 nobody,唉为什么就不行呢? 一路找到 ServerFault,说 nginx user 默认的是 nobody nobody(难道是这个原因。。。 好吧,那我就修改 nginx user 配置为 nobody admin

user                nobody admin;
worker_processes    1;

然后重启可以了

xhlwill avatar May 11 '17 16:05 xhlwill

通过这个方法,我没有解决,后面通过在usr/local/var/run/nginx下运行chmod -R 777 proxy_temp重启NGINX就可以了

summer996 avatar Mar 05 '19 09:03 summer996

...当我遇到这个问题的时候还来不及深究, 就已经解决了...

plh97 avatar Jun 06 '19 07:06 plh97

硬盘存储空间满也会出现这样的错误情况,清理出部分存储空间即可。

weibangtuo avatar Nov 27 '19 07:11 weibangtuo

Please remember to view nginx's error log... My problem is less disk space left:

2021/05/26 17:20:57 [warn] 10975#10975: *9 an upstream response is buffered to a temporary file /var/cache/nginx/proxy_temp/1/00/0000000001 while reading upstream, client: 120.244.60.127, server: dashboard.pongj.com, request: "GET /dashboard/bundles/dashboard.bundle.js HTTP/1.1", upstream: "http://127.0.0.1:10634/dashboard/bundles/dashboard.bundle.js", host: "dashboard.pongj.com", referrer: "https://dashboard.pongj.com/dashboard/apps"
2021/05/26 17:20:57 [crit] 10975#10975: *9 pwritev() "/var/cache/nginx/proxy_temp/1/00/0000000001" failed (28: No space left on#

The solution is free disk space #:sob:

hom avatar May 26 '21 09:05 hom