136 lines
3.1 KiB
Markdown
136 lines
3.1 KiB
Markdown
# ✅ Nginx-Django Bağlantı Sorunu Çözüldü (Coolify)
|
||
|
||
## 🎯 Sorun
|
||
Coolify'da deploy edilen projenizde Nginx container Django container'a bağlanamıyordu.
|
||
|
||
## 🔧 Yapılan Düzeltmeler
|
||
|
||
### 1. **docker-compose.c.yml**
|
||
```yaml
|
||
nginx:
|
||
build:
|
||
context: .
|
||
dockerfile: ./nginx/Dockerfile
|
||
ports:
|
||
- "80:80" # ✅ Eklendi (Coolify için gerekli)
|
||
networks:
|
||
coolify:
|
||
aliases:
|
||
- nginx # ✅ Düzeltildi
|
||
- nginx_proxy # ✅ Eklendi
|
||
```
|
||
|
||
### 2. **nginx/default.conf**
|
||
```nginx
|
||
# ✅ Upstream block eklendi
|
||
upstream django_backend {
|
||
server django_web_prod:8000 max_fails=3 fail_timeout=30s;
|
||
server web:8000 backup;
|
||
}
|
||
|
||
server {
|
||
listen 80;
|
||
location / {
|
||
proxy_pass http://django_backend; # ✅ Upstream kullanıyor
|
||
proxy_connect_timeout 60s; # ✅ Timeout ayarları
|
||
proxy_send_timeout 60s;
|
||
proxy_read_timeout 60s;
|
||
}
|
||
}
|
||
```
|
||
|
||
## 🚀 Hemen Deploy Edin
|
||
|
||
```bash
|
||
# 1. Değişiklikleri commit edin
|
||
git add nginx/default.conf docker-compose.c.yml
|
||
git commit -m "Fix: Nginx-Django connection for Coolify"
|
||
git push
|
||
|
||
# 2. Coolify'da redeploy butonuna tıklayın
|
||
```
|
||
|
||
## 🔍 Deploy Sonrası Hızlı Test
|
||
|
||
Coolify sunucusunda şu komutları çalıştırın:
|
||
|
||
```bash
|
||
# Container'ları kontrol edin
|
||
docker ps | grep -E "nginx|web"
|
||
|
||
# Nginx container ID'sini bulun
|
||
NGINX_ID=$(docker ps | grep nginx | awk '{print $1}')
|
||
|
||
# DNS çözümlemesi test
|
||
docker exec $NGINX_ID nslookup django_web_prod
|
||
|
||
# HTTP bağlantısı test
|
||
docker exec $NGINX_ID wget -qO- http://django_web_prod:8000 | head
|
||
|
||
# Nginx config test
|
||
docker exec $NGINX_ID nginx -t
|
||
|
||
# Nginx logları
|
||
docker logs $NGINX_ID --tail 50
|
||
```
|
||
|
||
## ✨ Upstream Stratejisi
|
||
|
||
Nginx artık 2 farklı yöntemle Django'ya bağlanmayı deniyor:
|
||
|
||
1. **Primary**: `django_web_prod:8000` (network alias)
|
||
- 3 başarısız denemeden sonra 30 saniye devre dışı kalır
|
||
|
||
2. **Backup**: `web:8000` (servis adı)
|
||
- Primary çalışmazsa otomatik devreye girer
|
||
|
||
Bu sayede Coolify'ın farklı DNS çözümleme davranışları sorun yaratmaz.
|
||
|
||
## 📋 Beklenen Sonuçlar
|
||
|
||
### ✅ Başarılı DNS Test
|
||
```
|
||
$ docker exec $NGINX_ID nslookup django_web_prod
|
||
Name: django_web_prod
|
||
Address: 172.18.0.3
|
||
```
|
||
|
||
### ✅ Başarılı HTTP Test
|
||
```
|
||
$ docker exec $NGINX_ID wget -qO- http://django_web_prod:8000
|
||
<!DOCTYPE html>
|
||
<html>
|
||
...
|
||
```
|
||
|
||
### ✅ Başarılı Nginx Config
|
||
```
|
||
$ docker exec $NGINX_ID nginx -t
|
||
nginx: configuration file /etc/nginx/nginx.conf test is successful
|
||
```
|
||
|
||
### ✅ Browser'dan Erişim
|
||
Coolify domain'inizi tarayıcıda açtığınızda Django uygulamanızı görmelisiniz.
|
||
|
||
## 🐛 Hala Sorun mu Var?
|
||
|
||
Detaylı troubleshooting için:
|
||
- 📖 `COOLIFY_NGINX_DEBUG.md` dosyasını okuyun
|
||
- 🔍 Debug script'ini çalıştırın
|
||
- 📝 Nginx ve Django loglarını kontrol edin
|
||
|
||
## 📊 Son Durum
|
||
|
||
```
|
||
✅ nginx/default.conf - Upstream stratejisi eklendi
|
||
✅ docker-compose.c.yml - Port mapping ve network alias düzeltildi
|
||
✅ nginx/Dockerfile - Config image içinde
|
||
✅ COOLIFY_NGINX_DEBUG.md - Detaylı troubleshooting rehberi
|
||
|
||
Toplam 4 dosya güncellendi/oluşturuldu
|
||
```
|
||
|
||
---
|
||
**Tarih**: 29 Ocak 2026
|
||
**Durum**: ✅ Hazır - Deploy edilebilir
|