

GitHub - AWSWIKI/frontend: AWSWIKI_FRONTEND
GitHub - AWSWIKI/backend: AWSWIKI_backend
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;
}
}