인프라/nginx
Nginx - location block
seungdols
2022. 5. 9. 13:41
location block
https://www.youtube.com/watch?v=3q2xxMc7XEo
Matching order
- = Exact match
- ^~ Preferential match
- ~ & *~ Regex match
- no mofier Prefix match
# Matches any prefix
# /greet
# /greeting
# /greet/something
location /greet {
return 200 'Hello from nginx prefix match location block';
}
# Exact match
location = /greet {
return 200 'Hello from nginx exact match location block';
}
# Regex match - case sensitive
# /greet123
location ~ /greet[0-9] {
return 200 'Hello from nginx case sensitive regex match location block';
}
# Regex match - case insensitive
#
location *~ /greet[0-9] {
return 200 'Hello from nginx case insensitive regex match location block';
}
# Prefix preferential match
# Same as location /greet, but more important than regex match
location ^~ /greet {
return 200 'Hello from nginx match with preferential over regex match location block';
}
반응형