
多数の言語ファイル (JSON 形式) を含むローカリゼーション フォルダーがあり、Web アプリはブラウザーの言語を読み取って対応する JSON ファイルを取得しようとします。
特定のシナリオでは、対応する言語ファイルが存在せず、nginx は当然ながら 404 を返します。ただし、デフォルトの言語ファイルへの一時的なリダイレクトを返したいと思います。
これを試してみましたが、うまくいかないようです。何が間違っているのでしょうか?
location /static/l10n {
try_files $uri @missing_language;
}
location @missing_language {
rewrite ^ /static/l10n/en-us.json break;
}
編集2: ということで、try_files
こんな感じで少し調整してみました。
location /static/l10n {
try_files $uri /static/l10n/en-us.json;
}
しかし、今度は 500 エラーが発生します。ログには次のように表示されます*35 rewrite or internal redirection cycle while internally redirecting
。
編集3: 私の完全な nginx conf はここにあります -https://gist.github.com/paambaati/9782e95b2e9af899b154
答え1
使用error_page
特定のファイルを404レスポンスとして使用するには、エラーページ:
location /static/l10n {
error_page 404 = /static/l10n/en-us.json;
}
http 200 として=
機能するの使用に注意してください。/static/l10n/en-us.json