在Angular 2中配置nginx时出错:无法加载资源:net :: ERR_CONTENT_LENGTH_MISMATCH [英] An error configuring nginx with Angular 2: Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH
问题描述
我将nginx.conf配置为将请求从Angular 2应用程序传输到tomcat应用程序.仍然有几个问题. 我的nginx.conf如下:
I configured nginx.conf to transfer the requests from Angular 2 application to the tomcat application. Still got several problems. My nginx.conf is as follows:
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正常工作,我看到欢迎使用nginx". Localhost:4200提供了角度应用. Localhost:8082无法打开localhost:4200和代理通行证( http://localhost:8080/rentapp/;)tomcat也不起作用.
The url localhost:8081 works fine, I see "Welcome to nginx". Localhost:4200 gives the angular application. Localhost:8082 does not open localhost:4200 and the proxy pass (http://localhost:8080/rentapp/;) to tomcat does not work either.
Chrome上的错误堆栈如下:
The error stack on the Chrome is as follows:
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
推荐答案
第一个需要设置日志记录,因此我在配置文件中注释了error_log:
First one needs to setup logging, so I commented out error_log in the configuration file:
error_log logs/nginx_error.log;
然后在日志中我可以看到:
Then in the log I could see:
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/"
日志在以下位置显示许可问题:
The log showed the permission problem on:
/usr/local/var/run/nginx/proxy_temp/1/00/0000000001
在此路径上固定权限可以解决问题
Fixing permissions on this path solved the problem
这篇关于在Angular 2中配置nginx时出错:无法加载资源:net :: ERR_CONTENT_LENGTH_MISMATCH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!