nginx 설정에서 location 블록 매칭 설정 방법 및 우선 순위 > 개발

본문 바로가기
사이트 내 전체검색

개발

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

페이지 정보

profile_image
작성자 관리자 (119.♡.119.69)
댓글 0건 조회 715회 작성일 25-03-19 15:49

본문

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.

추천0

댓글목록

등록된 댓글이 없습니다.

Total 408건 1 페이지
  • RSS
개발 목록
번호 제목 조회 추천 날짜
40891006-15
40793006-12
406147005-22
405264005-06
열람중716003-19
403747003-17
402982002-25
401812002-25
400848002-07
399837001-10
398844001-10
397879010-31
396888010-28
3951582009-23
3942517007-06
3931904007-02
3921723006-23
3912130006-23
3901710006-20
3891421006-15

검색


사이트 정보

Copyright © Baragi.Net. All rights reserved.