Browser error net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK) solution

This article has participated in the "Newcomer Creation Ceremony" event to start the road of gold creation together.

1. Find the problem

image.png

During the development process, when the front-end page loads css, js or woff, ttf files,  ERR_CONTENT_LENGTH_MISMATCH errors often occur. But not all js or css report errors, and the files that report errors are larger than those that do not report errors. And the file that reports the error can also be opened in the browser alone, so the simplest address error is ruled out. The frontend project is proxied by nginx, so you can check the nginx log to see if there are any clues.  

2. Solve the problem

Find nginx error log files

1. Find the nginx configuration file

ps -ef | grep nginx
复制代码

 The result is as follows:

www      16951 18739  0 16:15 ?        00:00:00 nginx: worker process
www      16952 18739  0 16:15 ?        00:00:00 nginx: worker process
www      16953 18739  0 16:15 ?        00:00:00 nginx: worker process
www      16954 18739  0 16:15 ?        00:00:00 nginx: worker process
www      16955 18739  0 16:15 ?        00:00:00 nginx: worker process
www      16956 18739  0 16:15 ?        00:00:00 nginx: worker process
www      16957 18739  0 16:15 ?        00:00:00 nginx: worker process
www      16958 18739  0 16:15 ?        00:00:00 nginx: worker process
root     18739     1  0 Sep20 ?        00:00:26 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
复制代码

My development environment nginx configuration file path is: /usr/local/nginx/conf/nginx.conf

2. View the error log file location

cat /usr/local/nginx/conf/nginx.conf
复制代码

image.png

My development environment nginx error log path is: cnk_data/nginx_logs/error.log

3. Open the error log

Filter according to the error file (if the file is too large, please wait a moment):

cat /cnk_data/nginx_logs/error.log | grep "jquery.dataTables.min.js"
复制代码

 The result is as follows:

2019/10/16 16:11:37 [crit] 5878#0: *81035 mkdir() "/usr/local/openresty/nginx/proxy_temp/2/35" failed (13: Permission denied) while reading upstream, client: 123.116.114.84, server: sunct.goapi.youlai.cn, request: "GET /static/js/adminone/jquery.dataTables.min.js HTTP/1.1", upstream: "http://127.0.0.1:9092/static/js/adminone/jquery.dataTables.min.js", host: "sunct.goapi.youlai.cn", referrer: "http://sunct.goapi.youlai.cn/admin/index"
复制代码

There is a mkdir() Permission denied error:

2019/10/16 16:11:36 [crit] 5881#0: *80999 mkdir() "/usr/local/openresty/nginx/proxy_temp/1/35" failed (13: Permission denied) while reading upstream, client: 123.116.114.84, server: sunct.goapi.youlai.cn, request: "GET /static/js/adminone/jquery.dataTables.min.js HTTP/1.1", upstream: "http://127.0.0.1:9092/static/js/adminone/jquery.dataTables.min.js", host: "sunct.goapi.youlai.cn", referrer: "sunct.goapi.youlai.cn/admin/index"

到此,可以得知是没有mkdir() 成功,结果因为没有权限,导致了请求失败,被拒绝。

那么,为什么nginx要访问proxy_temp文件夹呢?

因为proxy_temp是nginx的缓存文件夹,我的css和js文件过大了,所以nginx一般会从缓存里面去拿,而不是每次都去原地址直接加载。

4、尝试解决

进入报错的路径,我的是  /usr/local/openresty/nginx/,查看文件夹proxy_temp 权限。

cd /usr/local/openresty/nginx

ll
复制代码

结果如下(注:这是改后的权限)

image.png

根据个人情况,给proxy_temp 文件夹重新修改权限和组 即可。

chown www root proxy_temp

chmod -Rf 777 proxy_temp
复制代码

5、重启 nginx 服务

根据自己的nginx 服务配置来重启即可,命令可能如下:

./nginx -s reload
复制代码

I am using:

/etc/init.d/nginx reload
复制代码

6. Refresh the browser

Perfect, everything works!

image.png

image.png



END

If you have any questions, please leave a message below.

Or follow my official account " 孙三苗" ( sunsanmiao), enter “联系方式". Get further help.

Guess you like

Origin juejin.im/post/7085588832522862600