Skip to content

Commit f7786f5

Browse files
committed
refactor: nginx.conf.template 추가
1 parent c2c385e commit f7786f5

File tree

2 files changed

+82
-4
lines changed

2 files changed

+82
-4
lines changed

deployment/deploy.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ echo "Start docker-compose pull..."
1313
docker-compose pull dev-chat-backend-$NEW_COLOR
1414
docker-compose pull dev-chat-frontend-$NEW_COLOR
1515

16-
ACTIVE_COLOR_FILE="$(dirname "$0")/../active_color.txt"
16+
ACTIVE_COLOR_FILE="$(dirname "$0")/active_color.txt"
1717

1818
# active_color.txt 없으면 초기값 blue 생성
1919
if [ ! -f "$ACTIVE_COLOR_FILE" ]; then
@@ -75,8 +75,8 @@ fi
7575

7676

7777
# nginx upstream 설정 파일 변경 (green -> blue / blue -> green)
78-
sed -i "s/dev-chat-backend-$ACTIVE_COLOR/dev-chat-backend-$NEW_COLOR/g" ./nginx.conf
79-
sed -i "s/dev-chat-frontend-$ACTIVE_COLOR/dev-chat-frontend-$NEW_COLOR/g" ./nginx.conf
78+
sed -i "s/dev-chat-backend-$ACTIVE_COLOR/dev-chat-backend-$NEW_COLOR/g" ./nginx_proxy/nginx.conf
79+
sed -i "s/dev-chat-frontend-$ACTIVE_COLOR/dev-chat-frontend-$NEW_COLOR/g" ./nginx_proxy/nginx.conf
8080

8181
# nginx reload
8282
docker exec nginx_proxy nginx -s reload
@@ -86,6 +86,6 @@ docker-compose stop dev-chat-backend-$ACTIVE_COLOR
8686
docker-compose stop dev-chat-frontend-$ACTIVE_COLOR
8787

8888
# active_color.txt 업데이트
89-
echo $NEW_COLOR > "$(dirname "$0")/../active_color.txt"
89+
echo $NEW_COLOR > "$(dirname "$0")/active_color.txt"
9090

9191
echo "배포 완료: 현재 활성화된 서비스는 $NEW_COLOR 입니다."

nginx.conf.template

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
events { }
2+
3+
http {
4+
upstream frontend {
5+
server dev-chat-frontend-${ACTIVE_COLOR}:80; # React 컨테이너
6+
}
7+
8+
upstream backend {
9+
server dev-chat-backend-${ACTIVE_COLOR}:8080; # Spring Boot 컨테이너
10+
}
11+
12+
server {
13+
listen 80;
14+
server_name thedevchat.duckdns.org;
15+
16+
# HTTP -> HTTPS 리다이렉트
17+
return 301 https://$host$request_uri;
18+
}
19+
20+
server {
21+
listen 443 ssl;
22+
server_name thedevchat.duckdns.org;
23+
24+
ssl_certificate /etc/letsencrypt/live/thedevchat.duckdns.org/fullchain.pem;
25+
ssl_certificate_key /etc/letsencrypt/live/thedevchat.duckdns.org/privkey.pem;
26+
27+
ssl_protocols TLSv1.2 TLSv1.3;
28+
ssl_ciphers HIGH:!aNULL:!MD5;
29+
30+
# React 프론트엔드 프록시
31+
location / {
32+
proxy_pass http://frontend;
33+
proxy_http_version 1.1;
34+
35+
proxy_set_header Host $host;
36+
proxy_set_header X-Real-IP $remote_addr;
37+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
38+
proxy_set_header X-Forwarded-Proto $scheme;
39+
40+
# SPA 라우팅을 위한 fallback 설정
41+
proxy_intercept_errors on;
42+
error_page 404 = /index.html;
43+
}
44+
45+
# API 요청은 백엔드로 프록시
46+
location /api/ {
47+
proxy_pass http://backend/;
48+
proxy_http_version 1.1;
49+
50+
proxy_set_header Host thedevchat.duckdns.org;
51+
proxy_set_header X-Real-IP $remote_addr;
52+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
53+
proxy_set_header X-Forwarded-Proto $scheme;
54+
55+
proxy_cache_bypass $http_upgrade;
56+
}
57+
58+
# WebSocket 프록시
59+
location /ws {
60+
proxy_pass http://backend;
61+
proxy_http_version 1.1;
62+
63+
proxy_set_header Upgrade $http_upgrade;
64+
proxy_set_header Connection "Upgrade";
65+
66+
proxy_set_header Host thedevchat.duckdns.org;
67+
proxy_set_header X-Real-IP $remote_addr;
68+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
69+
proxy_set_header X-Forwarded-Proto $scheme;
70+
proxy_cache_bypass $http_upgrade;
71+
}
72+
73+
# index.html 직접 서빙용 (에러 발생시 대응)
74+
location = /index.html {
75+
proxy_pass http://frontend/index.html;
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)