Express和Nginx网路:: ERR_CONTENT_LENGTH_MISMATCH [英] Express and nginx net::ERR_CONTENT_LENGTH_MISMATCH

查看:84
本文介绍了Express和Nginx网路:: ERR_CONTENT_LENGTH_MISMATCH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Express驱动的网站,该网站正在通过nginx代理.有时在浏览器中加载页面时,会显示以下信息:

I'm developing an Express-driven site, that is going through an nginx proxy. Sometimes when loading a page in the browser, I get this:

GET http://myapp.local/css/bootstrap.css net::ERR_CONTENT_LENGTH_MISMATCH

如果刷新页面,它通常会消失.但是,如果一遍又一遍地刷新,它将再次出现.

If I refresh the page, it usually goes away. But if refresh over and over and over, it will come up again.

这是什么问题?我该怎么办才能缩小问题范围?这是我用于该服务器的 nginx conf:

What is the problem here? What can I do to narrow down the issue here? Here is my nginx conf for this server:

server {
  listen 80;
  server_name www.myapp.local;
  rewrite ^(.*) http://myapp.local$1 permanent;
}

server {
  listen 80;
  server_name myapp.local;

  access_log /vagrant/nginx/logs/myapp.local/access.log;
  error_log /vagrant/nginx/logs/myapp.local/error.log;

  location / {
    proxy_pass http://localhost:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

这肯定与nginx代理有关.因为如果我仅使用IP地址和节点端口访问该站点: http://10.10.10.10:8080 ,那么我永远也不会收到错误消息.但是,如果我使用代理的虚拟主机: http://myapp.local 进行访问,那么我最终将收到错误消息(我看到错误的可能性可能是十分之一).

This is definitely something to do with the nginx proxy. Because if I access the site using just the IP address and Node port: http://10.10.10.10:8080 then I never ever get the error. But if I access it using the proxied vhost: http://myapp.local then I will eventually get the error (maybe 1 out of 10 chance I see it).

推荐答案

net :: ERR_CONTENT_LENGTH_MISMATCH 是一个缓存问题.您要告诉Nginx如果满足某些条件(在您的情况下为 $ http_upgrade ),则绕过缓存.

The net::ERR_CONTENT_LENGTH_MISMATCH is a caching issue. You're telling Nginx to bypass the cache if certain conditions are met (in your case $http_upgrade).

您应该已经在某个配置文件中为nginx指定了缓存位置.一个快速的解决方法是删除该文件夹的内容,重新启动nginx,然后尝试再次访问该站点.另一个以缓存为代价的快速解决方案是删除 proxy_cache_bypass $ http_upgrade;

You should've specified the caching location for nginx in a configuration file somewhere. A quick fix will be to delete the contents of this folder, restart nginx, and then try accessing the site again. Another quick fix at the expense of caching is to remove the line proxy_cache_bypass $http_upgrade;

如果您提供有关缓存设置的更多详细信息,也许可以改善此答案.

If you provide more details on your caching setup, perhaps this answer could be improved.

这篇关于Express和Nginx网路:: ERR_CONTENT_LENGTH_MISMATCH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆