Files
dj52/COOLIFY_NO_PORT_MAPPING.md
Beyhan Oğur ec28a2024d first commit
2026-04-26 22:22:29 +03:00

255 lines
6.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ✅ Coolify Deployment - Doğru Yapılandırma
## 🎯 Önemli: Port Mapping Yok!
Coolify kendi reverse proxy'sini kullanır, bu yüzden:
-**`ports: - "80:80"` kullanmayın** (conflict yaratır)
-**Sadece `expose: - 80`** kullanın (internal)
-**Coolify labels eklenmeli** (Coolify'ın nginx'i bulması için)
## 📋 Güncel Yapılandırma
### docker-compose.c.yml (nginx servisi)
```yaml
nginx:
build:
context: .
dockerfile: ./nginx/Dockerfile
expose:
- 80 # ✅ Internal port (Coolify için)
networks:
coolify:
aliases:
- nginx
- nginx_proxy
labels:
- "coolify.managed=true" # ✅ Coolify tarafından yönetiliyor
- "coolify.http.port=80" # ✅ Coolify'a hangi port dinlediğini söyler
```
## 🔄 Coolify Proxy Akışı
```
Internet
Coolify Reverse Proxy (Caddy/Traefik)
[your-domain.com]
Internal: nginx:80 (exposed, not published)
Internal: django_web_prod:8000
Django App
```
## 🚀 Deploy Adımları
### 1. Git Push
```bash
git add docker-compose.c.yml
git commit -m "Fix: Remove port mapping for Coolify proxy"
git push
```
### 2. Coolify Dashboard
1. Projenize gidin
2. **Settings****General**
3. **Port** kısmında `80` olduğunu doğrulayın
4. **Redeploy** butonuna tıklayın
### 3. Domain Ayarları
Coolify'da:
- **Domains** sekmesinde domain'inizi ekleyin
- Coolify otomatik olarak SSL sertifikası alacak (Let's Encrypt)
- Coolify proxy'si nginx container'ın 80 portuna yönlendirecek
## 🔍 Test Komutları
Deploy sonrası Coolify sunucusunda:
```bash
# Container'ları kontrol edin
docker ps | grep -E "nginx|web"
# Nginx container ID
NGINX_ID=$(docker ps | grep nginx | head -1 | awk '{print $1}')
# Internal DNS testi (nginx container içinden)
docker exec $NGINX_ID nslookup django_web_prod
# Internal HTTP testi
docker exec $NGINX_ID wget -qO- http://django_web_prod:8000 | head
# Nginx config doğrulama
docker exec $NGINX_ID nginx -t
# Nginx logları
docker logs $NGINX_ID --tail 50
# Coolify network kontrolü
docker network inspect coolify | grep -A 5 "nginx"
```
## ✅ Başarı Kriterleri
- [ ] `docker ps` - Nginx container çalışıyor, **port mapping YOK** (80/tcp yazıyor ama 0.0.0.0:80->80/tcp yazmıyor)
- [ ] Internal DNS - `docker exec $NGINX_ID nslookup django_web_prod` çalışıyor
- [ ] Internal HTTP - `docker exec $NGINX_ID wget http://django_web_prod:8000` çalışıyor
- [ ] Nginx config - `docker exec $NGINX_ID nginx -t` başarılı
- [ ] **Browser** - Coolify domain'den (örn: https://yourdomain.com) site açılıyor
- [ ] **SSL** - Coolify otomatik HTTPS yönlendirmesi çalışıyor
## 📊 Beklenen `docker ps` Çıktısı
```bash
CONTAINER ID IMAGE PORTS NAMES
abc123 nginx:alpine 80/tcp django_nginx # ✅ Doğru (exposed)
def456 python:3.14 8000/tcp django_web_prod # ✅ Doğru (exposed)
# ❌ YANLIŞ olacak:
# 0.0.0.0:80->80/tcp # Bu Coolify ile conflict yaratır
```
Port sütununda sadece `80/tcp` görünmeli, `0.0.0.0:80->80/tcp` **görünmemeli**.
## 🐛 Sorun Giderme
### Problem: "Port 80 already in use"
**Sebep**: `ports:` tanımı hala var.
**Çözüm**:
```yaml
# ❌ YANLIŞ
nginx:
ports:
- "80:80"
# ✅ DOĞRU
nginx:
expose:
- 80
```
### Problem: "502 Bad Gateway" (Coolify domain'den)
**Sebep**: Coolify nginx container'ı bulamıyor.
**Çözüm**:
```bash
# Labels kontrolü
docker inspect $(docker ps | grep nginx | awk '{print $1}') | grep -A 5 "Labels"
# Beklenen:
# "coolify.managed": "true"
# "coolify.http.port": "80"
# Eğer yoksa docker-compose.c.yml'e ekleyin ve redeploy edin
```
### Problem: Nginx Django'ya bağlanamıyor
**Sebep**: Network alias veya DNS problemi.
**Çözüm**:
```bash
# Web container'ın network alias'ını kontrol edin
docker inspect $(docker ps | grep "web" | grep -v nginx | awk '{print $1}') | grep -A 10 "Aliases"
# Beklenen: "django_web_prod" görünmeli
# Eğer yoksa docker-compose.c.yml içinde web servisine ekleyin:
services:
web:
networks:
coolify:
aliases:
- django_web_prod
```
### Problem: Static/Media dosyaları yüklenmiyor
**Sebep**: Volume mount veya nginx config.
**Çözüm**:
```bash
# Volume kontrolü
docker exec $NGINX_ID ls -la /app/staticfiles/
docker exec $NGINX_ID ls -la /app/media/
# Eğer boşsa:
WEB_ID=$(docker ps | grep "web" | grep -v nginx | awk '{print $1}')
docker exec $WEB_ID python manage.py collectstatic --noinput
# Nginx config kontrolü
docker exec $NGINX_ID cat /etc/nginx/conf.d/default.conf | grep -A 3 "location /static"
```
## 🎯 Coolify'a Özel Notlar
### 1. Port Exposure
- Coolify container'ların **exposed** portlarını otomatik keşfeder
- `expose: - 80` yeterli, `ports:` gereksiz ve zararlı
### 2. Labels
```yaml
labels:
- "coolify.managed=true" # Coolify'ın yönetiminde
- "coolify.http.port=80" # HTTP trafiği için port
# - "coolify.https.port=443" # Eğer internal HTTPS varsa (şu an gerekli değil)
```
### 3. Network
```yaml
networks:
coolify:
external: true # Coolify tarafından oluşturulan network
```
### 4. Domain Routing
Coolify dashboard:
- **Domains** → Domain ekleyin (örn: `example.com`, `www.example.com`)
- **HTTPS** → Otomatik Let's Encrypt (default açık)
- **Redirect** → HTTP → HTTPS yönlendirme (önerilir)
### 5. Health Check
Coolify nginx'in sağlık durumunu kontrol eder:
- Dockerfile içindeki `HEALTHCHECK` direktifi kullanılır
- Eğer container unhealthy olursa otomatik restart edilir
## 📝 Checklist - Coolify Deploy
Öncesi:
- [ ] `ports:` tanımı **yok**, sadece `expose:` var
- [ ] Coolify labels eklenmiş
- [ ] Network `coolify` ve `external: true`
- [ ] `nginx/default.conf` upstream stratejisi var
- [ ] Git'e push edildi
Sonrası (Coolify Dashboard):
- [ ] Build başarılı
- [ ] Container başlatıldı
- [ ] Health check geçti
- [ ] Domain'e HTTPS ile erişim var
- [ ] Static/Media dosyaları yükleniyor
Sonrası (Terminal):
- [ ] `docker ps` - Nginx container çalışıyor (80/tcp)
- [ ] `docker exec ... nslookup django_web_prod` - Başarılı
- [ ] `docker exec ... wget http://django_web_prod:8000` - Django yanıtlıyor
- [ ] `docker exec ... nginx -t` - Config geçerli
- [ ] Nginx error.log temiz
## 🌐 Production Checklist
- [ ] **SSL**: Let's Encrypt sertifikası aktif
- [ ] **Redirect**: HTTP → HTTPS yönlendirme aktif
- [ ] **Static**: CSS/JS dosyaları yükleniyor
- [ ] **Media**: Kullanıcı yüklemeleri çalışıyor
- [ ] **Admin**: `/admin` paneli açılıyor
- [ ] **API**: API endpoint'leri yanıt veriyor
- [ ] **Logs**: Hata logları temiz
- [ ] **Monitoring**: Coolify metrics'te trafik görünüyor
---
**Oluşturulma**: 29 Ocak 2026
**Coolify Versiyonu**: v4.x
**Durum**: ✅ Production Ready