2017-08-24 1 views
2

My nginx vhost config-Inhalt:nginx: location =/{} Fehler

server { 
    listen 80; 
    server_name t.xianzhi.xxx.domain; 
    access_log /data/log/nginx/t.xianzhi.xxx.domain_access.log main; 

    location ~ /\. {deny all;} 

    proxy_set_header X-Real-IP  $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host   $host; 

    location =/{ 
     root /data/web/static/html; 
     index index.html; 
    } 

    location/{ 
     proxy_pass   http://127.0.0.1:9000; 
    } 

    location = /favicon.ico { 
     access_log off; 
     root /data/web/static/; 
    } 

    location = /apple-app-site-association { 
     add_header Content-Type "text/html; charset=utf-8"; 
     root /data/web/show/public/wap/; 
    } 

    location ~ \.(css|js|png|jpg|woff|ttf)$ { 
     root /data/web/static; 
     expires 10d; 
    } 

} 

Als Config, ich möchte Server den Pfad / zu /data/web/static/html/index.html und Server die anderen proxy_pass.

Die Wahrheit ist der Pfad / ist 404 nicht gefunden und die anderen sind erfolgreich.

Das Protokoll ist:

24/Aug/2017:10:49:43 +0800 10.5.17.37 t.xianzhi.xxx.domain - curl/7.51.0 - request:GET/HTTP/1.1 bbs:233status:404 upad:127.0.0.1:9000 rspt:0.017 rqtt:0.017 request_body:- 

Also, die / an Proxy übergeben.

Einige Informationen:

Die nginx Version: nginx/1.10.1

So, wie man es beheben?

Antwort

1

Das Problem ist Ihr = / Standort Block. Wenn Sie den Abschnitt

location =/{ 
    root /data/web/static/html; 
    index index.html; 
} 

betrachten, geben Sie den Stamm und Index.html an, aber Sie nichts Server. So sollten Sie es auf

ändern
location =/{ 
    root /data/web/static/html; 
    index index.html; 
    try_files /index.html =404; 
} 

oder

location =/{ 
    root /data/web/static/html; 
    try_files /index.html =404; 
} 
+0

Ich versuchte dies. Die gute Nachricht ist '/' Pfad ist jetzt hier abgestimmt. Und die schlechte Nachricht ist immer noch 404; Zur Unterscheidung ist meine Konfiguration 'try_files index.html = 502;'. Es gibt 502 zurück. Und ich kann bestätigen, dass die Datei '/ data/web/static/html/index.html' existiert. – Nil

+0

Lassen Sie mich etwas bestätigen, wenn dieser Block überhaupt aufgerufen wird oder nicht –

+0

So '=' Block wird aufgerufen. Überprüfen Sie, ob meine Änderungen helfen –