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

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

개발

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

페이지 정보

profile_image
작성자 관리자 (119.♡.119.69)
댓글 0건 조회 389회 작성일 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 404건 1 페이지
  • RSS
개발 목록
번호 제목 조회 추천 날짜
열람중390003-19
403389003-17
402543002-25
401498002-25
400558002-07
399543001-10
398610001-10
397603010-31
396669010-28
3951355009-23
3941846007-06
3931572007-02
3921480006-23
3911796006-23
3901456006-20
3891164006-15
3881254006-15
3871346005-27
3861758004-07
3852593002-02

검색


사이트 정보

Copyright © Baragi.Net. All rights reserved.