由于 net::ERR_CONTENT_LENGTH_MISMATCH,Javascript 未加载 [英] Javascript not loading due to net::ERR_CONTENT_LENGTH_MISMATCH
问题描述
我有一个在本地运行良好的应用程序,但在生产中却很糟糕.(经典问题,对吧?)
I've got an app that runs fine locally, but barfs in production. (Classic problem, right?)
在生产中,JS 未正确触发.当我打开浏览器控制台时,我看到这个错误:
In production, the JS isn't firing correctly. When I open up the browser console, I see this error:
net::ERR_CONTENT_LENGTH_MISMATCH
当我查看开发者工具的网络选项卡时,显示它在对 text/html 的 GET 请求中失败.
When I look in the network tab of Developer Tools, is shows that it failed on a GET request for text/html.
这是一个神秘的错误.我只找到了另外两个 SO 帖子,甚至提到了它们,但它们尚未解决.(有兴趣者:第一篇 和 第二篇文章)
It's a cryptic error. I've only found two other SO posts that even mention is and they're unsolved. (For the interested: first post and second post)
任何想法(1)它意味着什么或(2)如何解决它?
Any idea (1) what it means or (2) how to resolve it?
推荐答案
我收到错误:net::ERR_CONTENT_LENGTH_MISMATCH
I am getting Error: net::ERR_CONTENT_LENGTH_MISMATCH
查看您的服务器日志以确定真正的问题所在.
对我来说,问题出在 nginx 和文件权限之间:
For me the problem lay somewhere between nginx and file permissions:
tail -f/usr/local/var/log/nginx/error.log
或运行nginx -t
以确定您的 conf 位置,您可以在其中指定自定义日志路径.- 在浏览器中刷新资产,例如
http://localhost:3000/assets/jquery/jquery.js
tail -f /usr/local/var/log/nginx/error.log
or runnginx -t
to determine your conf location, where you could specify a custom log path.- refresh the asset in your browser, eg
http://localhost:3000/assets/jquery/jquery.js
您可能会在日志中看到类似的内容:
You may see something like this in the logs:
"/usr/local/var/run/nginx/proxy_temp/9/04/0000000049" 失败 (13:权限被拒绝)同时读取文件 xyz 的上游
"/usr/local/var/run/nginx/proxy_temp/9/04/0000000049" failed (13: Permission denied) while reading upstream for file xyz
这是我修复的方法:
sudo nginx -s stop
sudo rm -rf /usr/local/var/run/nginx/*
sudo nginx
这篇关于由于 net::ERR_CONTENT_LENGTH_MISMATCH,Javascript 未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!