回答:
これでうまくいくと思います:
location / {
try_files /base.html =404;
}
try_files '' /base.html;(の最初の引数として空の文字列はtry_files)と呼ばれるファイルの検索を回避します$uri。
try_files '' /base.html;リダイレクトの問題とサーバーの内部エラーが発生しましたが、try_files '' /base.html =404;誰かを助ける場合は修正して修正しました。
を使用してもtry_filesうまくいきませんでした。ログに書き換えまたは内部リダイレクトサイクルエラーが発生しました。
Nginxのドキュメントには、いくつかの追加の詳細があります:
http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files
だから私は次のことを使ってしまいました:
root /var/www/mysite;
location / {
try_files $uri /base.html;
}
location = /base.html {
expires 30s;
}
try_files '' /base.html =404;(上記を参照)
location = /base.html { expires 30s }。
これは私のために働きました:
location / {
alias /path/to/my/indexfile/;
try_files $uri /index.html;
}
これにより、JavaScriptの単一ページアプリのキャッチオールURLを作成できました。によって作成されたcss、フォント、JavaScriptなどのすべての静的ファイルnpm run build は、と同じディレクトリにある場合に見つかりindex.htmlます。
静的ファイルが別のディレクトリにある場合、何らかの理由で、次のようなものが必要になります。
# Static pages generated by "npm run build"
location ~ ^/css/|^/fonts/|^/semantic/|^/static/ {
alias /path/to/my/staticfiles/;
}
正しい方法は次のとおりです。
location / {
rewrite (.*) base.html last;
}
を使用lastするとlocation、書き換えの結果に応じて、nginxが新しい適切なブロックを見つけます。
try_files この問題に対する完全に有効なアプローチでもあります。