# Nginx ν•˜λ„€μŠ€ (Nginx Configuration Harness) ## πŸ“‹ κ°œμš” **root `/`와 `/admin` 경둜λ₯Ό κ²€μ¦ν•˜λŠ” Nginx ν•˜λ„€μŠ€**. --- ## 🎯 핡심 원칙 ``` 곡개 URL: https://www.taxbaik.com/ λ°±μ—”λ“œ: http://127.0.0.1:5001/ Nginx: 경둜 λ³€ν™˜ μ—†μŒ ``` --- ## πŸ“ μ„€μ • 파일 μœ„μΉ˜ ``` /etc/nginx/sites-available/taxbaik-domains.conf /etc/nginx/sites-enabled/taxbaik-domains.conf (심볼릭 링크) ``` --- ## πŸ”§ μ„€μ • ꡬ쑰 ### ν•„μˆ˜ server 블둝 ```nginx server { server_name taxbaik.com www.taxbaik.com; listen 443 ssl; ssl_certificate /etc/letsencrypt/live/taxbaik.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/taxbaik.com/privkey.pem; location / { proxy_pass http://127.0.0.1:5001/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; 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; } } ``` --- ## πŸ“Š 포트 λ§€ν•‘ κ·œμΉ™ | 도메인 | 포트 | ν”„λ‘œν† μ½œ | λ°±μ—”λ“œ 포트 | μƒνƒœ | |--------|------|---------|-----------|------| | **taxbaik.com** | 443 (HTTPS) | TLS 1.3 | 5001 (ν”„λ‘μ‹œ) | βœ… ν™œμ„± | | **taxbaik.com** | 80 (HTTP) | - | - | 301 λ¦¬λ‹€μ΄λ ‰νŠΈ | | **www.taxbaik.com** | 443 (HTTPS) | TLS 1.3 | 5001 (ν”„λ‘μ‹œ) | βœ… ν™œμ„± | | **www.taxbaik.com** | 80 (HTTP) | - | - | 301 λ¦¬λ‹€μ΄λ ‰νŠΈ | | **gitea.taxbaik.com** | 80 (HTTP) | HTTP | 3000 | βœ… ν™œμ„± | --- ## πŸš€ ν”„λ‘μ‹œ μ„€μ • (Proxy Configuration) ### proxy_pass κ·œμΉ™ **κ·œμΉ™ 1: μƒλŒ€κ²½λ‘œ μœ μ§€** ```nginx # βœ… μ˜¬λ°”λ¦„ (μŠ¬λž˜μ‹œ 있음) proxy_pass http://127.0.0.1:5001/; # κ²°κ³Ό: /admin/login β†’ http://127.0.0.1:5001/admin/login ``` **κ·œμΉ™ 2: 경둜 λ³€ν™˜ (ν•„μš”μ‹œλ§Œ)** ```nginx # βœ… 특수 경우: /v1/ β†’ /api/v1/ location /v1/ { proxy_pass http://127.0.0.1:5001/api/v1/; rewrite ^/v1/(.*)$ /api/v1/$1 break; # 이쀑 전달 λ°©μ§€ } ``` **κ·œμΉ™ 3: μ£Όμ˜μ‚¬ν•­** ```nginx # ❌ ν‹€λ¦Ό (μŠ¬λž˜μ‹œ μ—†μŒ, 경둜 이쀑 전달) proxy_pass http://127.0.0.1:5001; # κ²°κ³Ό: /admin β†’ http://127.0.0.1:5001 + /admin β†’ 이쀑 μŠ¬λž˜μ‹œ κ°€λŠ₯ # ❌ ν‹€λ¦Ό (rewrite 없이 proxy_pass만) location /api { proxy_pass http://127.0.0.1:5001/api/; } # κ²°κ³Ό: /api/users β†’ http://127.0.0.1:5001/api//users (이쀑 μŠ¬λž˜μ‹œ) ``` ### ν•„μˆ˜ 헀더 `location /`μ—λŠ” `proxy_http_version 1.1`, `Upgrade`, `Connection`, `Host`, `X-Real-IP`, `X-Forwarded-For`, `X-Forwarded-Proto`λ₯Ό μœ μ§€ν•œλ‹€. --- ## πŸ”’ SSL/TLS μ„€μ • ### Let's Encrypt μΈμ¦μ„œ `/etc/letsencrypt/live/taxbaik.com/fullchain.pem`κ³Ό `privkey.pem`을 μ‚¬μš©ν•œλ‹€. ### λ³΄μ•ˆ 헀더 `HSTS`, `nosniff`, `SAMEORIGIN`은 μœ μ§€ν•œλ‹€. --- ## ⚑ Green-Blue 배포와 Nginx ### 포트 μ „ν™˜ 원리 NginxλŠ” `5001` ν”„λ‘μ‹œμ—λ§Œ μ—°κ²°ν•˜κ³ , ν”„λ‘μ‹œκ°€ `~/taxbaik_port`λ₯Ό 읽어 `5003/5004` 쀑 ν™œμ„± 포트둜 보낸닀. Nginx에 `5003/5004`λ₯Ό 직접 ν•˜λ“œμ½”λ”©ν•˜μ§€ μ•ŠλŠ”λ‹€. --- ## πŸ” 검증 체크리슀트 - `sudo nginx -t` ν›„ `sudo systemctl reload nginx` - `http://www.taxbaik.com/`은 301, `https://www.taxbaik.com/`은 200 - `curl -H "Host: www.taxbaik.com" http://127.0.0.1/`은 HTML 응닡 - `https://www.taxbaik.com/api/blog?limit=1`은 JSON 응닡 --- ## πŸ†˜ 문제 ν•΄κ²° - 404: `http://127.0.0.1/` 응닡, `:5001` ν”„λ‘μ‹œ, `taxbaik_port` κ°’ 확인 - 502: Nginx μ—λŸ¬ 둜그, ν”„λ‘μ‹œ 둜그, `5003/5004` μ•± 포트 확인 - SSL 였λ₯˜: `letsencrypt` μΈμ¦μ„œ κ²½λ‘œμ™€ 만료일 확인 --- ## πŸ“ž μ°Έκ³  - **배포 ν•˜λ„€μŠ€**: `/docs/DEPLOYMENT_HARNESS.md` - **λΉŒλ“œ 검증**: `/docs/BUILD_VALIDATION_HARNESS.md` - **배포 슀크립트**: `/deploy_gb.sh`