diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2c7740b..105cb70 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -126,7 +126,7 @@ jobs: # 리포지토리 이름을 소문자로 변환 RAW_IMAGE_NAME="${{ github.repository }}" echo "GITHUB_REPOSITORY=${RAW_IMAGE_NAME,,}" >> .env - chmod 644 .env + chmod 600 .env # 생성된 .env와 필요한 소스들을(Sparse Checkout한것) 실행 위치로 복사한다. - name: Sync files to app directory diff --git a/nginx/conf.d/default.conf b/nginx/conf.d/default.conf index 1dbd468..2b266f7 100644 --- a/nginx/conf.d/default.conf +++ b/nginx/conf.d/default.conf @@ -20,6 +20,10 @@ server { ssl_certificate /etc/letsencrypt/live/api.ssambee.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/api.ssambee.com/privkey.pem; + # Rate Limit 상태 코드변경 (기본 503 -> 429) - 429는 Too Many Requests + limit_req_status 429; + limit_req_log_level warn; # 에러 로그에 기록되어 Fail2ban이 감지할 수 있게 + # 클라이언트 최대 업로드 크기 client_max_body_size 100M; @@ -30,6 +34,9 @@ server { return 301 https://www.ssambee.com; } + # 순간적으로 들어오는 50개 요청까지는 대기열로 - 대기열에 있는 요청도 지연 없이 즉시 + limit_req zone=api_limit burst=50 nodelay; + proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; @@ -40,8 +47,9 @@ server { proxy_set_header X-Forwarded-Proto $scheme; proxy_cache_bypass $http_upgrade; - # 타임아웃 설정 + # Cookie 설정 유지 proxy_cookie_domain api.ssambee.com .ssambee.com; + # 타임아웃 설정 proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; @@ -53,12 +61,15 @@ server { access_log off; } - # API 엔드포인트 (필요시) + # API 엔드포인트 location /api { if ($http_accept ~* "text/html") { return 301 https://www.ssambee.com; } + # api 요청: 더 엄격한 burst를 적용 + limit_req zone=api_limit burst=30 nodelay; + proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Host $host;