2017-03-03 7 views
0
server { 
listen 80; 
server_name _; 
access_log /data/wwwlogs/access_nginx.log combined; 
root /data/wwwroot/default; 
index index.html; 

location /dist { 
    try_files $uri $uri/ /dist/index.html; 
} 

私は自分のnginxサーバーを設定しようとしています。私は "ipaddress/dist/何でも"を訪問しようとすると、すべてのリクエストは "ipaddress/dist/index.html"にリダイレクトできます。 Angular2のルーティングの要件です。しかし、私は404ページしか見つけることができません。 "try_files"または "location/dist"が動作しないようです。どうしたの?ありがとうございました。Nginxの場所が動作しません

答えて

0

チェックアウトredirect指示。

server { 
    listen 80; 
    server_name localhost; 
    access_log /data/wwwlogs/access_nginx.log combined; 
    root /data/wwwroot/default; 
    index index.html; 

    location /dist { 
     try_files $uri $uri/ /dist/index.html; 
    } 

    rewrite ^/(.*)$ http://localhost/dist/index.html permanent; 
} 
+0

ありがとうございます。それは直接リダイレクトが2段階ルーティングアドレスを失うようです。 Angularが提供する解決策は、 "location"と "try_files"を使うことですが、私はうまく動作しません。 "$ uri"が見つからない場合、nginxは "try_files"の最後のparmに移動しません。 –

+0

あなたは場所/ {...}を試すことができますか? – OmarIlias

+0

いいえ、この 'location/{try_files $ uri /dist/index.html; } 'それは何と言いますか? – OmarIlias

0

あなたのサンプルが機能します。多分あなたは新しい設定でnginxサービスをリロードするのを忘れましたか?

+0

に何が起こっているのか把握してください。私は何かを変更するたびにリロードします.....ほとんど放棄します。 –

+0

'error_log /data/wwwlogs/error_nginx.log debug;を設定して何が起こっているのか把握しましたか? –

関連する問題