Naver Cloud Platform에 몇가지 기능의 부재로 프론트 소스 도메인 서비스를 위해 nginx를 통한 정적 리소스 서버를 구축하였고, 쿠버네티스와의 연동과 오케스트레이션을 위해 컨테이너 기반으로 구축하기로 하였다.
Nginx 설정
Resource serving 흐름 및 구성도

Nginx Configure – 전체적인 설정에 대한 설명

Nginx Configure – 세부 설명
location 문법 우선순위
regex | 적용 순위 | 설명 | 문법 |
= | 1 순위 | 완전 일치 | location = / { } |
^~ | 2 순위 | prefix 일치 | location ^~ / { } |
~ | 3 순위 | 대/소문자 일치 | location ~ ^/ { } |
~* | 4 순위 | 대/소문자 무시하고 일치 | location ~* ^/admin { } |
/ | 5 순위 | 하위 일치 | location / { } |
rewrite
rewrite regex replacement [flag]
▷ rewrite ^/student /fileUpload.html permanent;
flag | 설명 |
last | 현재 블록 안에서 rewrite 작업 후 다른 작업 처리 |
break | 현재 블록 안에서 rewrite 작업 후 다른 작업을 실행 후 종료 (다른 rewrite 실행하지 x) |
redirect | 302 Temporary Redirect |
permanent | 301 Permanent Redirect |
▶ 여기서 permanent를 사용한 이유?
요구사항
▷ Domain은 고정하고 path는 재 정의한 내용이 유지되며 NCP의 Object Storage의 Resource를 Serving
프로세스
1. Rewrite을 통해 Path를 재 정의 하고 영구적인 이동을 통해 nginx로 재요청한다.
a. test2.com/student 요청
b. rewrite ^/student /fileUpload.html permanent; 에서path를 변경하여
test2.com/fileUpload.html 요청
2. 들어온 요청을 NCP Object Storage로 Host를 고정하고 Reverse Proxy를 한다.
a. test2.com/fileUpload.html 요청
b. location ^~ /을 통해 “/”로 시작하는 모든 path를 해당 블록에서 처리
c. Host 고정 및 Object Storage로 Resource 요청 (하위 “발생한 이슈와 해결“ 내용 참조)
proxy

발생한 이슈와 해결 과정
1. “no resolver defined to resolve” 에러 발생
▷ dns 서버 IP를 resolver에 지정하여 해결
2. proxy_pass를 통해 Object Storage와 연결을 성공 하였으나 403 forbidden 권한에 관련된 response status 발생
▷ cdn+ 에 설정되어 있는 도메인 test1.com과 호스트 헤더 커스텀을 통해 변경된 test2.com의
도메인이 달라 발생하는 원인임을 파악
하나의 CDN에 두가지 도메인을 허용하도록 설정
- test1.com의 공개 도메인을 통한 접속
- ncp 도메인을 통한 접근과 접근 요청하는 origin host를 맞추어 줌으로서 403 해결
3. test2.com/student로 요청 하였을 경우 test2.com/fileUpload.html을 예상하였으나 origin host의 path가 변경되지 않고, ncp 요청에 대한 path만 rewrite 되는 현상 발생
▷ 1차적으로 rewrite를 통해 301 영구 리다이렉트를 먼저 작업하여 path 변경 이후 proxy_pass 하는 방식으로 변경
다음 장에서 Jenkins를 통한 이미지 빌드 배포와
k8s를 연동하고 컨테이너 서비스 하는 방법에 대해 정리하는 시간을 가지겠습니다.
'Server' 카테고리의 다른 글
[CSAP] NGINX Header Hide (0) | 2025.01.31 |
---|---|
[VM] Linux Buffer/Cache 정리 (0) | 2024.12.27 |
[Tomcat] MathType Container Server 구축기 (1) (0) | 2023.11.22 |
[NCP] Nginx를 이용한 Static Resource Container service 구축기(2) (1) | 2023.11.13 |
Web Server와 ServletContainer의 통신 (AJP) (0) | 2022.12.02 |
댓글