워크북 | Notion

  1. 도커파일, 이미지
    1. 기본 이미지 파일
    2. 이미지 경량화
  2. 명령어로 실행
    1. 명령어 실행 과정
  3. docker compose
    1. 노드 1개 구조도
  4. docker stack
    1. 마스터 3개, 워커 2개 구조도
    2. docker stack 알고리즘
  5. 모니터링

우리 팀 구조도

Untitled

Untitled

Frontend code

GitHub - AWSWIKI/frontend: AWSWIKI_FRONTEND

Backend code

GitHub - AWSWIKI/backend: AWSWIKI_backend

도커 파일

Nginx

FROM nginx:1.25.4-alpine
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
events {
    worker_connections  1024; # Nginx 워커 프로세스 당 최대 연결 수를 설정.
}

http {
    upstream frontend {
        server frontend_service:3000; # 프론트엔드 서비스로의 요청을 처리할 서버 정의.
    }

    upstream haproxy_backend {
        server haproxy:10001; # HAProxy로의 요청을 처리할 백엔드 서버 정의. 
    }

    server {
        listen 80 default_server; # Nginx가 80 포트에서 수신 대기하도록 설정. 이 포트는 HTTP 트래픽을 위한 기본 포트.

        location / {
            proxy_pass <http://frontend>; # 루트 경로("/")에 대한 요청을 프론트엔드 업스트림으로 전달.

            # CORS 헤더 추가
            # 다른 출처에서의 요청을 허용하기 위한 CORS 관련 헤더를 추가합니다.
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
            add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization' always;

            # OPTIONS 요청에 대한 사전 처리를 정의합니다.
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';
                add_header 'Access-Control-Max-Age' 1728000; # 사전 요청의 결과를 캐시하는 시간(초)
                add_header 'Content-Type' 'text/plain; charset=utf-8';
                add_header 'Content-Length' 0;
                return 204; # 실제 컨텐츠 없이 204 상태 코드를 반환합니다.
            }
        }

        location /api {
            proxy_pass http://haproxy_backend; # "/api" 경로에 대한 요청을 HAProxy 백엔드 업스트림으로 전달.
            # 프록시 요청에 필요한 헤더를 설정합니다.
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }