【问题标题】:An error configuring nginx with Angular 2: Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH使用 Angular 2 配置 nginx 时出错:无法加载资源:net::ERR_CONTENT_LENGTH_MISMATCH
【发布时间】:2017-05-27 01:42:15
【问题描述】:

我配置了 nginx.conf 以将请求从 Angular 2 应用程序传输到 tomcat 应用程序。还是有几个问题。 我的 nginx.conf 如下:

worker_processes  1;
events {
worker_connections  1024;
}
http {
include       mime.types;
default_type  application/octet-stream;
sendfile        on;
keepalive_timeout  65;
server {
    listen          8082;
    root /;
    client_max_body_size 50M;
    location /images {
    root /var/www/rentoptimum;
    }
    location / {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:4200/;
    }
    location /api/ {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:8080/rentapp/;
    }
}
server {
    listen       8081;
    server_name  localhost;
    location / {
        root   html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
include servers/*;
}

url localhost:8081 工作正常,我看到“Welcome to nginx”。本地主机:4200 给出了角度应用程序。 localhost:8082 不打开 localhost:4200 并且代理传递 (http://localhost:8080/rentapp/;) 到 tomcat 也不起作用。

Chrome上的错误栈如下:

Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH
inline.bundle.js:53 Uncaught TypeError: Cannot read property 'call' of undefined
 at __webpack_require__ (inline.bundle.js:53)
 at Object.1022 (main.bundle.js:6)
 at __webpack_require__ (inline.bundle.js:53)
 at webpackJsonpCallback (inline.bundle.js:24)
at main.bundle.js:1

【问题讨论】:

    标签: angular tomcat nginx


    【解决方案1】:

    第一个需要设置日志,所以我在配置文件中注释掉了error_log:

    error_log  logs/nginx_error.log; 
    

    然后在日志中我可以看到:

    2017/05/27 22:37:29 [crit] 41617#0: *1 open() "/usr/local/var/run/nginx/proxy_temp/1/00/0000000001" failed (13: Permission denied) while reading upstream, client: 127.0.0.1, server: localhost, request: "GET /vendor.bundle.js HTTP/1.1", upstream: "http://127.0.0.1:4200/vendor.bundle.js", host: "localhost:8082", referrer: "http://localhost:8082/"
    

    日志显示权限问题:

    /usr/local/var/run/nginx/proxy_temp/1/00/0000000001
    

    修复此路径的权限解决了问题

    【讨论】:

      【解决方案2】:

      在我的情况下,此错误是由于磁盘已完全使用(100% 已使用)造成的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-24
        • 2014-04-16
        • 2020-03-22
        • 1970-01-01
        • 2018-04-08
        • 2020-11-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多