nginx 설정에서 location 블록 매칭 설정 방법 및 우선 순위
페이지 정보

본문
nginx 설정에서 location 블록 매칭 설정 방법 및 우선 순위
## 매칭 설정 구문
1. 기본 매칭
여기서는 depth 가 깊을 수록 우선순위가 높다.
```
location / {}
location /page/ {}
```
2. 정규식 매칭
~ 를 사용하고, * 가 있으면 대소문자를 구분하지 않는다.
```
location ~ \.(gif|jpg|jpeg)$ {}
location ~* \.(gif|jpg|jpeg)$ {}
```
3. prefix 매칭 - 접두사? 매칭
^~ 를 사용한다. 정규식의 시작 기호와 비슷한 기능인듯..
```
location ^~ /images/ {}
```
4. exact match of URI and location - 정확한 매칭
= 를 사용한다.
```
location = / {}
location = /img/icon.gif {}
```
## 우선순위
위의 매칭 방법에서 뒤로 갈수록 우선순위가 높다.
즉, 4 > 3 > 2 > 1
## 공식문서
** 출처 : https://nginx.org/en/docs/http/ngx_http_core_module.html#location
```
location = / {
[ configuration A ]
}
location / {
[ configuration B ]
}
location /documents/ {
[ configuration C ]
}
location ^~ /images/ {
[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ {
[ configuration E ]
}
```
The “/” request will match configuration A,
the “/index.html” request will match configuration B,
the “/documents/document.html” request will match configuration C,
the “/images/1.gif” request will match configuration D,
and the “/documents/1.jpg” request will match configuration E.
## 매칭 설정 구문
1. 기본 매칭
여기서는 depth 가 깊을 수록 우선순위가 높다.
```
location / {}
location /page/ {}
```
2. 정규식 매칭
~ 를 사용하고, * 가 있으면 대소문자를 구분하지 않는다.
```
location ~ \.(gif|jpg|jpeg)$ {}
location ~* \.(gif|jpg|jpeg)$ {}
```
3. prefix 매칭 - 접두사? 매칭
^~ 를 사용한다. 정규식의 시작 기호와 비슷한 기능인듯..
```
location ^~ /images/ {}
```
4. exact match of URI and location - 정확한 매칭
= 를 사용한다.
```
location = / {}
location = /img/icon.gif {}
```
## 우선순위
위의 매칭 방법에서 뒤로 갈수록 우선순위가 높다.
즉, 4 > 3 > 2 > 1
## 공식문서
** 출처 : https://nginx.org/en/docs/http/ngx_http_core_module.html#location
```
location = / {
[ configuration A ]
}
location / {
[ configuration B ]
}
location /documents/ {
[ configuration C ]
}
location ^~ /images/ {
[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ {
[ configuration E ]
}
```
The “/” request will match configuration A,
the “/index.html” request will match configuration B,
the “/documents/document.html” request will match configuration C,
the “/images/1.gif” request will match configuration D,
and the “/documents/1.jpg” request will match configuration E.
추천0
댓글목록
등록된 댓글이 없습니다.