Deployment — ขึ้น Production จริง
เปลี่ยนจาก localhost → โดเมนจริง + HTTPS + scale ได้
Architecture สำหรับ production
Internet
│
▼
┌────────────────┐
│ Cloudflare │ (option — CDN + DDoS)
└────────┬───────┘
│
┌────────▼───────┐
│ Nginx (HTTPS) │ Let's Encrypt
└────────┬───────┘
│
┌───────────┼───────────┐
▼ ▼ ▼
shop.com api.shop.com /store
(Nuxt) (Nest API) (Nuxt — same)
│ │
└─────┬─────┘
▼
┌─────────────────┐
│ PostgreSQL + Redis │
│ (managed) │
└────────────────────┘
เตรียมก่อน deploy
1. ซื้อโดเมน
yourshop.comapi.yourshop.com- (option)
m.yourshop.com— ถ้าจะแยก mobile web
ชี้ DNS A record → IP ของ server
2. เลือก hosting
| Type | แนะนำ | ราคา |
|---|---|---|
| Beginner | Vercel (web) + Railway (api+db) | ~$10-30/เดือน |
| Standard | DigitalOcean Droplet 4GB | $24/เดือน |
| Scale | AWS (EC2 + RDS + S3) | $50+/เดือน |
Method A — Docker Compose (ง่ายสุด, all-in-one VPS)
Step 1 — เตรียม VPS
# SSH เข้า server
ssh root@<server-ip>
# ติดตั้ง docker
curl -fsSL https://get.docker.com | sh
# clone source
git clone <your-repo> /opt/ecommerce
cd /opt/ecommerce
cp .env.example .env
Step 2 — แก้ env เป็น production
nano .env
# Database
POSTGRES_PASSWORD=<openssl rand -base64 32>
# JWT
JWT_ACCESS_SECRET=<openssl rand -hex 32>
JWT_REFRESH_SECRET=<openssl rand -hex 32>
# CORS — ต้องเป็นโดเมนจริง
CORS_ORIGINS=https://yourshop.com
# Web → API
NUXT_PUBLIC_API_BASE=https://api.yourshop.com/api/v1
NUXT_PUBLIC_APP_NAME=YourShop
Step 3 — Start stack
docker compose up -d
docker compose ps # check
Step 4 — Migration
docker compose exec api npx prisma migrate deploy
# (option) seed
docker compose exec api npx prisma db seed
Step 5 — Nginx + HTTPS
ใช้ config ที่อยู่ใน infra/nginx/:
# ติดตั้ง
sudo apt update
sudo apt install nginx certbot python3-certbot-nginx
# copy config
sudo cp infra/nginx/lumora.conf /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/lumora.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
# ออก HTTPS cert
sudo certbot --nginx -d yourshop.com -d api.yourshop.com -d www.yourshop.com
# auto-renew (cert หมดอายุทุก 90 วัน)
sudo systemctl enable certbot.timer
✅ พร้อมใช้ที่ https://yourshop.com
Method B — Vercel (web) + VPS (api)
Web — Vercel
cd ecommerce-web
npx vercel
ใน Vercel dashboard:
- ใส่ env variables:
NUXT_PUBLIC_API_BASE=https://api.yourshop.com/api/v1NUXT_PUBLIC_APP_NAME=YourShop
- ผูกโดเมน:
yourshop.com - Deploy
ข้อดี: auto-deploy ตอน push git, edge CDN, HTTPS auto
API + DB — VPS
ทำเฉพาะ Method A step 1-4 (รัน api + postgres + redis ผ่าน docker-compose)
Method C — Vercel + Railway (managed all)
ทุกอย่าง managed:
- Push code ขึ้น GitHub
- Vercel: New Project → import
ecommerce-web - Railway:
- New Project → Deploy from GitHub → เลือก
ecommerce-api -
- Add PostgreSQL service
-
- Add Redis service
- New Project → Deploy from GitHub → เลือก
- ตั้ง env ของ Railway:
DATABASE_URL(auto จาก PostgreSQL service)REDIS_URLJWT_*CORS_ORIGINS
- Vercel env:
NUXT_PUBLIC_API_BASE=<Railway api URL>
ข้อดี: zero-ops, auto-scale, ตั้งครั้งเดียวจบ
Production Checklist
Security ✅
- [ ] JWT secrets เป็นค่าสุ่ม (≥32 chars)
- [ ] Database password แข็งแรง (≥20 chars)
- [ ] HTTPS เปิดทุก domain
- [ ] CORS origin = domain จริง (ไม่ใช่
*) - [ ] Rate limit เปิด
- [ ]
npm auditไม่มี high/critical
Database ✅
- [ ] Backup อัตโนมัติ (ดู 09 — Maintenance)
- [ ] Migration deploy เรียบร้อย
- [ ] ลบ seed data ของ test
- [ ] Index ตรวจสอบแล้ว
Performance ✅
- [ ] CDN รูป (Cloudflare / Bunny / Imgix)
- [ ] Redis cache เปิด
- [ ] gzip / brotli ใน Nginx
- [ ] Lighthouse ≥ 90 (Performance + SEO + A11y)
Monitoring ✅
- [ ] Sentry / Bugsnag — error tracking
- [ ] UptimeRobot — uptime monitor
- [ ] Database connection alert
- [ ] Disk space alert (server)
Content ✅
- [ ] Logo + favicon = ของจริง
- [ ] OG image — ลอง share LINE/Facebook ดู preview
- [ ] นโยบายความเป็นส่วนตัว + Terms + Return policy
- [ ] ติดต่อร้านใน footer (เบอร์/อีเมล/address)
Legal (ประเทศไทย) ✅
- [ ] จดทะเบียนพาณิชย์อิเล็กทรอนิกส์
- [ ] PDPA: privacy policy + consent banner
- [ ] ใบกำกับภาษี (ถ้า VAT)
Custom Domain ตรวจสอบ
หลัง deploy:
- ✅
https://yourshop.comโหลดได้ - ✅
http://yourshop.comredirect → https - ✅
https://www.yourshop.comredirect → non-www (หรือกลับกัน) - ✅
https://api.yourshop.com/docs(Swagger) เห็น - ✅ ลอง login จริงผ่าน production URL
- ✅ ลอง upload สลิป → ขึ้น storage จริง
ทดสอบบนมือถือจริง
หลัง deploy + แอปอัปขึ้น store:
- โหลดแอปจาก App Store / Play Store
- login
- ทำ Flow A ครบ (ดู test/04-flows)
Update / Re-deploy
Method A (Docker)
cd /opt/ecommerce
git pull
docker compose build --no-cache api web
docker compose up -d
docker compose exec api npx prisma migrate deploy
Method B (Vercel)
- push git → auto-deploy
Method C (Railway)
- push git → auto-deploy
Rollback
Docker Compose
git checkout <previous-commit>
docker compose build --no-cache
docker compose up -d
Vercel — กดปุ่ม “Promote to Production” ใน deployment history
ขั้นต่อไป
- ดู maintenance + backup → 09 — Maintenance
- FAQ → 10 — FAQ
