【问题标题】:net::ERR_CONTENT_LENGTH_MISMATCH on nginx 1.8.0nginx 1.8.0 上的 net::ERR_CONTENT_LENGTH_MISMATCH
【发布时间】:2015-11-11 22:28:03
【问题描述】:

当我注意到 angular 无法使用 net::ERR_CONTENT_LENGTH_MISMATCH 加载时,问题就开始了。

错误的完整列表:

GET http://xyx.com/assets/angular/angular.js?body=1 net::ERR_CONTENT_LENGTH_MISMATCH
Uncaught ReferenceError: angular is not defined(anonymous function) @ angular-cookie.js?body=1:7
Uncaught ReferenceError: angular is not defined(anonymous function) @ ui-bootstrap-tpls.js?body=1:9
Uncaught TypeError: Cannot read property 'isDefined' of undefined(anonymous function) @ angular-ui-router.js?body=1:19(anonymous function) @ angular-ui-router.js?body=1:4340
Uncaught ReferenceError: angular is not defined(anonymous function) @ ng-optimizely.js?body=1:1
Uncaught TypeError: Cannot read property '$$minErr' of undefined(anonymous function) @ angular-resource.js?body=1:9(anonymous function) @ angular-resource.js?body=1:628
Uncaught ReferenceError: angular is not defined

我做了一些研究,导致我检查了 nginx 错误日志。日志产生以下错误:

2015/11/11 16:26:31 [crit] 39125#0: *255 open() "/usr/local/var/run/nginx/proxy_temp/4/00/0000000004" failed (13: Permission denied) while reading upstream, client: x.x.x.x, server: xyx.com, request: "GET /assets/angular/angular.js?body=1 HTTP/1.1", upstream: "http://x.x.x.x:9090/assets/angular/angular.js?body=1", host: "xyz.com", referrer: "url_here"

我发现有类似问题的post。但是删除/usr/local/var/run/nginx目录的内容并重启nginx并没有解决问题。

我还验证了 nginx 工作进程正在由 /usr/local/var/run/nginx/proxy_temp 目录的同一所有者运行,正如另一个 post 中提到的(用户是nobody)。将权限更改为 777 也不起作用。

这个问题发生在我的开发环境中。我正在使用带有 El Capitan (10.11.1) 和 nginx 版本 1.8.0 的 Mac。对此的任何帮助将不胜感激。

nginx 配置文件:

server {
  listen 80;

  server_name www.local.site.com;
  return 301 https://local.site.com$request_uri;
}

server {
  listen 80;
  server_name local.sell.site.com;

  location / {
    proxy_pass http://x.x.x.x:9090;
  }
}

server {
  listen 443;
  server_name local.sell.site.com;

  ssl on;
  ssl_certificate /Users/sheldon/Repos/site/config/nginx/ssl/site.crt;
  ssl_certificate_key /Users/sheldon/Repos/site/config/nginx/ssl/site.key;
  ssl_session_timeout  5m;
  ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers "[Removed]";
  ssl_prefer_server_ciphers on;


  location / {
    proxy_pass http://x.x.x.x:9090;
  }
}

server {
  listen 443;

  root /Users/sheldon/Repos/site/www;
  index index.php;
  server_name local.site.com;
  access_log /Users/sheldon/logs/nginx/local.site.com.access.log;
  error_log /Users/sheldon/logs/nginx/local.site.com.error.log;

  ssl on;
  ssl_certificate /Users/sheldon/Repos/site/config/nginx/ssl/site.crt;
  ssl_certificate_key /Users/sheldon/Repos/site/config/nginx/ssl/site.key;
  ssl_session_timeout  5m;
  ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers "[Removed]";
  ssl_prefer_server_ciphers on;

  large_client_header_buffers 4 8m;

  location ~* (.+)\.(\d+)\.(js|css|png|jpg|jpeg|gif)$ {
    try_files $uri $1.$3;
  }

  location / {
      index index.html index.php;
      try_files $uri $uri/ @handler;
      expires 30d;
  }

  location ^~ /media/downloadable/ { deny all; }

  location  /. {
      return 404;
  }

  location @handler {
      rewrite / /index.php;
  }

  location ~ .php/ {
      rewrite ^(.*.php)/ $1 last;
  }

  location ~ \.php$ {
      if (!-e $request_filename) {
      rewrite / /index.php last;
      }
      expires off;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/tmp/php5-fpm.sock;
      fastcgi_index index.php;
      fastcgi_intercept_errors on;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param MAGE_RUN_TYPE store;
      fastcgi_param ENVIRONMENT dev;
      fastcgi_param MAGE_IS_DEVELOPER_MODE true;
      fastcgi_buffer_size 128k;
      fastcgi_buffers 4 256k;
      fastcgi_busy_buffers_size 256k;
      fastcgi_read_timeout 420;
      include fastcgi_params;
  }

  location /api { 
      rewrite ^/api/rest /api.php?type=rest; 
  }
}

【问题讨论】:

    标签: javascript angularjs nginx


    【解决方案1】:

    您还必须向运行 nginx 的用户授予足够的权限,以访问托管您的上游 http://x.x.x.x:9090 并拥有您部署的源代码的目录。

    【讨论】:

    • 我在本地运行 nginx,刚刚尝试将我的存储库中包含此项目源代码的所有文件和目录更改为无人用户。这样做并重新启动 nginx 后,我仍然遇到同样的问题。你知道还有什么问题吗?
    • 你能分享你的nginx的配置文件吗..你可以把它放在问题本身
    • 我已经为相关站点添加了 nginx 配置。请有空的时候看看。 @msoliman
    • x.x.x.x:9090 在哪里托管在同一台机器或不同的机器上? .. 你能从安装了 nginx 版本的当前机器访问这个 URL
    • 这个 x.x.x.x:9090 应该是真实的 IP 地址。如果您将您的后端服务器托管在同一台机器上,请将其设置为127.0.0.1:9090,否则请指定真实 IP
    猜你喜欢
    • 2017-03-12
    • 2014-11-16
    • 2016-02-13
    • 2014-06-13
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 2015-05-04
    • 2015-04-28
    相关资源
    最近更新 更多