2017-05-27 5 views
0

Ich habe nginx.conf konfiguriert, um die Anfragen von der Angular 2-Anwendung an die Tomcat-Anwendung zu übertragen. Immer noch einige Probleme. Mein nginx.conf ist wie folgt:Fehler beim Konfigurieren von nginx mit Angular 2: Fehler beim Laden der Ressource: net :: ERR_CONTENT_LENGTH_MISMATCH

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/*; 
} 

Die URL localhost: 8081 funktioniert gut, ich sehe „Welcome to nginx“. Localhost: 4200 gibt die eckige Anwendung. Localhost: 8082 öffnet localhost: 4200 nicht und der Proxy-Pass (http://localhost:8080/rentapp/;) an tomcat funktioniert auch nicht.

Der Fehler-Stack auf dem Chrome ist wie folgt:

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 

Antwort

0

Zuerst ein Setup-Protokollierung benötigt, so kommentierte ich error_log in der Konfigurationsdatei aus:

error_log logs/nginx_error.log; 

Dann im Protokoll I sehen kann:

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/" 

Das Protokoll zeigte, dass das Berechtigungsproblem auf:

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

Fixing Berechtigungen auf diesem Weg das Problem gelöst

Verwandte Themen