Nginx HTTP Proxy 서버

zuckerfrei·2023년 8월 28일
0

nginx

목록 보기
2/2

1. 배경

기존에는 LB → WAS → DB의 구조를 가지고 있었다.
그러나 고객사는 보안을 명분으로 LB → WEB → WAS → DB의 구조로 변경하길 원했다.

이럴 경우 WEB에서는 단순 http proxy 기능만 수행하면 된다.

여러 proxy서버 종류 중 nginx를 선택한 이유는 단순히 이 서버가 http proxy만 수행 하면 되기 때문이다.

만약 로드밸런싱이나 SSL 인증서까지 합쳐진 역할이라면 HAProxy를 사용하는 것이 관리 측면에서 나을 수 있다.
우리의 경우 로드밸런싱, SSL 인증서는 기존 NCP LB를 사용하는 편이 현재 구성상 더 관리하기 편하고 변화가 적을 것이라 판단했다.


2. 구성도

가상의 ip로 구성도 작성

기존 구성도

변경 구성도


3. 작업

3-1. nginx 설치

RHEL 8.6
참조

# 확인하기 
[root@web-srv ~]# yum module list nginx

# default 버전 변경 
[root@web-srv ~]# yum module enable nginx:1.20

# 변경 확인 
[root@web-srv ~]# yum module list nginx
...
Government Naver Cloud Platform RHEL Repository 8.6 AppStream additional
Name                                             Stream                                              Profiles                                              Summary
nginx                                            1.14 [d]                                            common [d]                                            nginx webserver
nginx                                            1.16                                                common [d]                                            nginx webserver
nginx                                            1.18                                                common [d]                                            nginx webserver
nginx                                            1.20 [e]                                            common [d]                                            nginx webserver

# 설치
[root@web-srv ~]# dnf install -y nginx:1.20
Updating Subscription Management repositories.
Unable to read consumer identity
...
=====================================================================================================================
 Package              Arch     Version                                       Repository                         Size
=====================================================================================================================
Installing:
 nginx                x86_64   1:1.20.1-1.module+el8.6.0+13722+f063ea60      rhel-8-server-8.6-iso-AppStream   593 k
Installing dependencies:
 nginx-filesystem     noarch   1:1.20.1-1.module+el8.6.0+13722+f063ea60      rhel-8-server-8.6-iso-AppStream    26 k
 redhat-logos-httpd   noarch   84.5-1.el8                                    rhel-8-server-8.6-iso-BaseOS       29 k

3-2. nginx.conf 백업 및 수정

/etc/nginx/nginx.conf
참조

...

http {

    ...
    
    # -------- SVC-1 -------
    upstream svc-1 {
        server 10.0.10.7:8000;
    }
    server {
        listen 8000;
        server_name 10.0.110.*;

        location / {
            proxy_pass http://svc-1;
        }
    }

    # ------- SVC-2 -------
    upstream svc-2 {
        server 10.0.10.7:8001;
    }
    server {
        listen 8001;
        server_name 10.0.110.*;
        location / {
            proxy_pass http://svc-2;
        }
    }
    
    ...
}

3-3. 설정값 설명

  • upstream.server
    • 넘겨줄 타겟 서버, 포트
  • http.server.listen
    • 클라이언트의 요청을 수신할 포트
  • http.server.server_name
    • 클라이언트 호스트 이름
    • 여기서는 서비스 LB 서브넷 전체(*)로 설정함 참조

3-4. log 경로

default 경로는 아래와 같다.

/var/log/nginx/

nginx가 알아서 하루치 로그를 gz로 압축 해놓아서 로그 용량도 크게 쌓이지 않는다.

profile
무설탕 음료를 좋아합니다

0개의 댓글