ロケーション ディレクティブはどのような順序で実行されますか?
ベストアンサー1
- クエリに正確に一致する「=」プレフィックスを持つディレクティブ。見つかった場合は、検索が停止します。
- 残りのすべてのディレクティブは、通常の文字列です。この一致で「^~」プレフィックスが使用されている場合、検索は停止します。
- 構成ファイルで定義されている順序での正規表現。
- #3 が一致した場合はその結果が使用されます。それ以外の場合は、#2 の一致が使用されます。
ドキュメントからの例:
location = / {
# matches the query / only.
[ configuration A ]
}
location / {
# matches any query, since all queries begin with /, but regular
# expressions and any longer conventional blocks will be
# matched first.
[ configuration B ]
}
location /documents/ {
# matches any query beginning with /documents/ and continues searching,
# so regular expressions will be checked. This will be matched only if
# regular expressions don't find a match.
[ configuration C ]
}
location ^~ /images/ {
# matches any query beginning with /images/ and halts searching,
# so regular expressions will not be checked.
[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ {
# matches any request ending in gif, jpg, or jpeg. However, all
# requests to the /images/ directory will be handled by
# Configuration D.
[ configuration E ]
}
それでもまだ混乱するなら、より詳しい説明はこちら。