LoginSignup
18

More than 5 years have passed since last update.

posted at

Nginxのtry_filesディレクティブ設定例

Nginxの設定にて、静的なファイルと動的なURLを振り分けたいことがあります。try_filesを利用すれば、指定した順番で確認と転送を実施してくれます。

参考
Module ngx_http_core_module

以下の順番で確認するよう設定します
1. URLのパスにファイルがあるか
2. 1がなかった場合、URLのパスにディレクトリがあるか
3. 12がなかった場合、指定したロケーションに行く

location / {
    root /home/user/app/public/;
    try_files $uri $uri/ @dinamic;
}

location @dinamic {
    proxy_pass http://upstream;
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
18