nginx 에서 if 구문을 중첩해서 사용하는 방법 > 개발

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

개발

nginx 에서 if 구문을 중첩해서 사용하는 방법

페이지 정보

profile_image
작성자 관리자 (119.♡.119.69)
댓글 0건 조회 388회 작성일 25-03-17 20:08

본문

** 참고 : https://sub0709.tistory.com/69


## nginx 에서 if 구문을 아래처럼 사용할 수 없다.

```
if ($uri = '특정URI' && $request_method = 'POST') {
}

if ($uri = '특정URI') { 
if ($request_method = 'POST') { 
}
}
```


## 해결방법

아래와 같은 방식으로 사용할 수 있다. 꼼수.
```
if ($uri = '특정URI') {
set $STEP A;
}
if ($request_method = 'POST') {
set $STEP "${STEP}B";
}
if ($STEP = 'AB') { 
return 404;
}
```


## 해결방법 2

** 참고 : https://akageun.github.io/2018/01/12/nginx-multiple-if-statements.html
```
// 이렇게 할 수 없다.
//if ($host = 'a.example.com' || $host = 'b.example.com'){
//    return 301 https://$host$request_uri;
//}

set $is_redirect_val 0;

if ($host = 'a.example.com') {
    set $is_redirect_val 1;
}
if ($host = 'b.example.com') {
    set $is_redirect_val 1;
}
if ($is_redirect_val = 1) {
    return 301 https://$host$request_uri;
}
```

추천0

댓글목록

등록된 댓글이 없습니다.

Total 404건 1 페이지
  • RSS
개발 목록
번호 제목 조회 추천 날짜
404389003-19
열람중389003-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.