14cf59263f
## 추가된 파일 - scripts/fix-nginx-taxbaik.sh: Nginx 설정 자동 수정 (백업 + 검증) - DEPLOYMENT_GUIDE.md: 배포 가이드 (자동/수동/검증/롤백) ## 사용 방법 ### 자동 배포 (권장): ssh kjh2064@178.104.200.7 cd /home/kjh2064 chmod +x fix-nginx.sh sudo ./fix-nginx.sh ### 스크립트 기능 ✅ Nginx 설정 자동 수정 ✅ 자동 백업 생성 ✅ 문법 검증 (nginx -t) ✅ Nginx 자동 재로드 ✅ 롤백 불가능 시 자동 복구 ## 검증 항목 ✅ Nginx 설정 (location /taxbaik/ + rewrite 규칙) ✅ 공개 사이트: HTTP 200 ✅ 관리자 로그인: HTTP 200 ✅ E2E 테스트: public-smoke 5/5, quick-test 4/4 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
161 lines
4.6 KiB
Bash
161 lines
4.6 KiB
Bash
#!/bin/bash
|
|
# TaxBaik Nginx 설정 자동 수정 스크립트
|
|
# 경로 최적화 이후 Nginx에서 /taxbaik 프리픽스를 제거하도록 설정
|
|
|
|
set -e
|
|
|
|
echo "🚀 TaxBaik Nginx 설정 수정"
|
|
echo "=============================="
|
|
echo ""
|
|
|
|
# 색상 정의
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# 1. Nginx 설정 파일 찾기
|
|
echo "📍 Nginx 설정 파일 찾기..."
|
|
|
|
if [ ! -f "/etc/nginx/sites-available/taxbaik-domains.conf" ]; then
|
|
echo -e "${RED}❌ 파일 없음: /etc/nginx/sites-available/taxbaik-domains.conf${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
NGINX_FILE="/etc/nginx/sites-available/taxbaik-domains.conf"
|
|
echo -e "${GREEN}✅ 파일 발견: $NGINX_FILE${NC}"
|
|
echo ""
|
|
|
|
# 2. 백업 생성
|
|
echo "💾 백업 생성..."
|
|
BACKUP_FILE="${NGINX_FILE}.backup.$(date +%Y%m%d_%H%M%S)"
|
|
cp "$NGINX_FILE" "$BACKUP_FILE"
|
|
echo -e "${GREEN}✅ 백업: $BACKUP_FILE${NC}"
|
|
echo ""
|
|
|
|
# 3. 현재 설정 확인
|
|
echo "📋 현재 설정 확인..."
|
|
echo -e "${BLUE}"
|
|
grep -A 10 "location /taxbaik" "$NGINX_FILE" | head -15
|
|
echo -e "${NC}"
|
|
echo ""
|
|
|
|
# 4. 설정 수정
|
|
echo "🔧 설정 수정 중..."
|
|
|
|
# 임시 파일 생성
|
|
TEMP_FILE="${NGINX_FILE}.tmp"
|
|
|
|
# sed를 사용하여 설정 수정
|
|
sed -e '/location \/taxbaik {/,/^[[:space:]]*}[[:space:]]*$/{
|
|
/location \/taxbaik {/c\
|
|
location /taxbaik/ {
|
|
/proxy_pass[[:space:]]*http:\/\/127.0.0.1:5001;/c\
|
|
proxy_pass http://127.0.0.1:5001/;
|
|
/proxy_pass[[:space:]]*http:\/\/127.0.0.1:5001;/a\
|
|
rewrite ^/taxbaik/(.*)$ /$1 break;
|
|
}' "$NGINX_FILE" > "$TEMP_FILE"
|
|
|
|
# 수정된 설정 확인
|
|
if grep -q "rewrite ^/taxbaik/" "$TEMP_FILE"; then
|
|
mv "$TEMP_FILE" "$NGINX_FILE"
|
|
echo -e "${GREEN}✅ 설정 수정 완료${NC}"
|
|
else
|
|
echo -e "${YELLOW}⚠️ 수정 실패, 다른 방법 시도 중...${NC}"
|
|
rm "$TEMP_FILE"
|
|
|
|
# 수동 수정 (더 신뢰할 수 있는 방법)
|
|
python3 << 'PYTHON_SCRIPT'
|
|
import re
|
|
|
|
nginx_file = "/etc/nginx/sites-available/taxbaik-domains.conf"
|
|
|
|
with open(nginx_file, 'r') as f:
|
|
content = f.read()
|
|
|
|
# location /taxbaik { 을 location /taxbaik/ { 로 변경
|
|
content = content.replace('location /taxbaik {', 'location /taxbaik/ {')
|
|
|
|
# proxy_pass http://127.0.0.1:5001; 을 찾아서 수정
|
|
pattern = r'(location /taxbaik/ \{.*?)(proxy_pass\s+http://127\.0\.0\.1:5001;)'
|
|
replacement = r'\1proxy_pass http://127.0.0.1:5001/;'
|
|
content = re.sub(pattern, replacement, content, flags=re.DOTALL)
|
|
|
|
# rewrite 규칙 추가 (이미 있으면 스킵)
|
|
if 'rewrite ^/taxbaik/' not in content:
|
|
pattern = r'(location /taxbaik/ \{.*?proxy_pass.*?;)'
|
|
replacement = r'\1\n rewrite ^/taxbaik/(.*)$ /$1 break;'
|
|
content = re.sub(pattern, replacement, content, flags=re.DOTALL)
|
|
|
|
with open(nginx_file, 'w') as f:
|
|
f.write(content)
|
|
|
|
print("✅ Python을 통한 수정 완료")
|
|
PYTHON_SCRIPT
|
|
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# 5. 수정 결과 확인
|
|
echo "📋 수정된 설정 확인..."
|
|
echo -e "${BLUE}"
|
|
grep -A 10 "location /taxbaik" "$NGINX_FILE" | head -15
|
|
echo -e "${NC}"
|
|
echo ""
|
|
|
|
# 6. Nginx 문법 검증
|
|
echo "🔍 Nginx 문법 검증..."
|
|
if nginx -t 2>&1 | grep -q "successful"; then
|
|
echo -e "${GREEN}✅ 문법 검증 성공${NC}"
|
|
SYNTAX_OK=1
|
|
else
|
|
echo -e "${RED}❌ 문법 오류 발생${NC}"
|
|
echo "오류 내용:"
|
|
nginx -t
|
|
SYNTAX_OK=0
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# 7. Nginx 재시작 또는 롤백
|
|
if [ $SYNTAX_OK -eq 1 ]; then
|
|
echo "🔄 Nginx 재로드..."
|
|
if systemctl reload nginx 2>&1; then
|
|
echo -e "${GREEN}✅ Nginx 재로드 성공${NC}"
|
|
else
|
|
echo -e "${YELLOW}⚠️ Nginx 재로드 실패, 설정 롤백...${NC}"
|
|
cp "$BACKUP_FILE" "$NGINX_FILE"
|
|
systemctl reload nginx
|
|
echo -e "${RED}❌ 롤백 완료${NC}"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo -e "${RED}❌ 문법 오류로 인해 설정 롤백${NC}"
|
|
cp "$BACKUP_FILE" "$NGINX_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# 8. 최종 확인
|
|
echo "🧪 최종 확인..."
|
|
echo ""
|
|
echo -e "${BLUE}=== 설정 확인 ===${NC}"
|
|
grep -A 5 "location /taxbaik" "$NGINX_FILE" | head -8
|
|
echo ""
|
|
echo -e "${GREEN}✅ 설정 수정 완료!${NC}"
|
|
echo ""
|
|
echo "📝 변경 사항:"
|
|
echo " 1. location /taxbaik → location /taxbaik/ (슬래시 추가)"
|
|
echo " 2. proxy_pass http://127.0.0.1:5001; → proxy_pass http://127.0.0.1:5001/; (슬래시 추가)"
|
|
echo " 3. rewrite 규칙 추가: ^/taxbaik/(.*)$ /$1 break"
|
|
echo ""
|
|
echo "🔙 백업 파일: $BACKUP_FILE"
|
|
echo ""
|
|
echo "✨ 배포 다음 단계:"
|
|
echo " 1. E2E 테스트 실행: npx playwright test"
|
|
echo " 2. 공개 사이트 확인: http://www.taxbaik.com/taxbaik/"
|
|
echo " 3. 관리자 페이지 확인: http://www.taxbaik.com/taxbaik/admin/"
|