439 lines
9.6 KiB
Markdown
439 lines
9.6 KiB
Markdown
|
|
# 🌐 Nginx Proxy Manager Kurulum Rehberi
|
|||
|
|
|
|||
|
|
Oltalama Panel için Nginx Proxy Manager (NPM) ile reverse proxy kurulumu.
|
|||
|
|
|
|||
|
|
## 📋 Neden Tek Domain?
|
|||
|
|
|
|||
|
|
**Önerilen Yapı:** Tek domain, path-based routing
|
|||
|
|
|
|||
|
|
### Avantajları:
|
|||
|
|
- ✅ **CORS Sorunu Yok**: Frontend ve backend aynı origin'de
|
|||
|
|
- ✅ **Tek SSL Sertifikası**: Sadece bir domain için sertifika
|
|||
|
|
- ✅ **Basit Yönetim**: Tek entry point
|
|||
|
|
- ✅ **Kolay Kurulum**: Daha az konfigürasyon
|
|||
|
|
|
|||
|
|
### Alternatif: İki Subdomain
|
|||
|
|
|
|||
|
|
Eğer iki ayrı subdomain kullanmak isterseniz:
|
|||
|
|
- `panel.yourdomain.com` → Frontend
|
|||
|
|
- `api.yourdomain.com` → Backend
|
|||
|
|
|
|||
|
|
**Not:** Bu durumda CORS ayarları gerekir ve iki SSL sertifikası gerekir.
|
|||
|
|
|
|||
|
|
## 🚀 Nginx Proxy Manager Kurulumu
|
|||
|
|
|
|||
|
|
### 1. Docker ile NPM Kurulumu
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# Docker ve Docker Compose kurulumu (eğer yoksa)
|
|||
|
|
sudo apt update
|
|||
|
|
sudo apt install docker.io docker-compose -y
|
|||
|
|
|
|||
|
|
# NPM dizini oluştur
|
|||
|
|
mkdir -p ~/nginx-proxy-manager
|
|||
|
|
cd ~/nginx-proxy-manager
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**docker-compose.yml:**
|
|||
|
|
|
|||
|
|
```yaml
|
|||
|
|
version: '3'
|
|||
|
|
services:
|
|||
|
|
app:
|
|||
|
|
image: 'jc21/nginx-proxy-manager:latest'
|
|||
|
|
restart: unless-stopped
|
|||
|
|
ports:
|
|||
|
|
- '80:80' # HTTP
|
|||
|
|
- '443:443' # HTTPS
|
|||
|
|
- '81:81' # Admin Panel
|
|||
|
|
volumes:
|
|||
|
|
- ./data:/data
|
|||
|
|
- ./letsencrypt:/etc/letsencrypt
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# NPM başlat
|
|||
|
|
docker-compose up -d
|
|||
|
|
|
|||
|
|
# Logları izle
|
|||
|
|
docker-compose logs -f
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. NPM Admin Paneline Giriş
|
|||
|
|
|
|||
|
|
1. Tarayıcıdan `http://sunucu-ip:81` adresine gidin
|
|||
|
|
2. İlk giriş bilgileri:
|
|||
|
|
- Email: `admin@example.com`
|
|||
|
|
- Şifre: `changeme`
|
|||
|
|
3. Giriş yaptıktan sonra **mutlaka** email ve şifreyi değiştirin
|
|||
|
|
|
|||
|
|
## 🔧 Tek Domain Konfigürasyonu (Önerilen)
|
|||
|
|
|
|||
|
|
### Adım 1: Proxy Host Ekle
|
|||
|
|
|
|||
|
|
NPM Admin Panel → **Hosts** → **Proxy Hosts** → **Add Proxy Host**
|
|||
|
|
|
|||
|
|
#### Details Sekmesi:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
Domain Names: yourdomain.com
|
|||
|
|
www.yourdomain.com
|
|||
|
|
|
|||
|
|
Scheme: http
|
|||
|
|
Forward Hostname: localhost (veya Oltalama sunucusunun IP'si)
|
|||
|
|
Forward Port: 4173
|
|||
|
|
|
|||
|
|
☑ Cache Assets
|
|||
|
|
☑ Block Common Exploits
|
|||
|
|
☑ Websockets Support
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### SSL Sekmesi:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
SSL Certificate: Request a new SSL Certificate
|
|||
|
|
|
|||
|
|
☑ Force SSL
|
|||
|
|
☑ HTTP/2 Support
|
|||
|
|
☑ HSTS Enabled
|
|||
|
|
☑ HSTS Subdomains
|
|||
|
|
|
|||
|
|
Email Address: youremail@example.com
|
|||
|
|
☑ I Agree to the Let's Encrypt Terms of Service
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
#### Advanced Sekmesi:
|
|||
|
|
|
|||
|
|
**Custom Nginx Configuration:**
|
|||
|
|
|
|||
|
|
```nginx
|
|||
|
|
# Backend API routing
|
|||
|
|
location /api {
|
|||
|
|
proxy_pass http://localhost:3000;
|
|||
|
|
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;
|
|||
|
|
proxy_cache_bypass $http_upgrade;
|
|||
|
|
|
|||
|
|
# Timeouts
|
|||
|
|
proxy_connect_timeout 60s;
|
|||
|
|
proxy_send_timeout 60s;
|
|||
|
|
proxy_read_timeout 60s;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# Tracking endpoint
|
|||
|
|
location /t/ {
|
|||
|
|
proxy_pass http://localhost:3000;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
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;
|
|||
|
|
|
|||
|
|
# No cache for tracking
|
|||
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|||
|
|
add_header Pragma "no-cache";
|
|||
|
|
add_header Expires "0";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# Health check endpoint
|
|||
|
|
location /health {
|
|||
|
|
proxy_pass http://localhost:3000;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# Frontend static files
|
|||
|
|
location / {
|
|||
|
|
proxy_pass http://localhost:4173;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Upgrade $http_upgrade;
|
|||
|
|
proxy_set_header Connection 'upgrade';
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_cache_bypass $http_upgrade;
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Adım 2: Oltalama Panel Ayarları
|
|||
|
|
|
|||
|
|
Panele giriş yapın → **Ayarlar** → **Genel Ayarlar**
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
Domain (Base URL): https://yourdomain.com
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Önemli:**
|
|||
|
|
- Protokolü ekleyin: `https://`
|
|||
|
|
- Sondaki `/` karakterini eklemeyin
|
|||
|
|
- Subdomain kullanıyorsanız: `https://panel.yourdomain.com`
|
|||
|
|
|
|||
|
|
## 🔀 İki Domain Konfigürasyonu (Alternatif)
|
|||
|
|
|
|||
|
|
### Oltalama Panel Ayarları
|
|||
|
|
|
|||
|
|
Panele giriş yapın → **Ayarlar** → **Genel Ayarlar**
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
☑ İki Ayrı Domain Kullan (CORS Aktif Et)
|
|||
|
|
Backend Domain: https://api.yourdomain.com
|
|||
|
|
Frontend Domain: https://panel.yourdomain.com
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Önemli:**
|
|||
|
|
- CORS checkbox'ını işaretleyin
|
|||
|
|
- Her iki domain'i de `https://` ile girin
|
|||
|
|
- Sondaki `/` karakterini eklemeyin
|
|||
|
|
|
|||
|
|
## 🔀 Nginx Proxy Manager - İki Domain Kurulumu
|
|||
|
|
|
|||
|
|
Eğer backend ve frontend'i ayırmak isterseniz:
|
|||
|
|
|
|||
|
|
### Backend Proxy Host
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
Domain Names: api.yourdomain.com
|
|||
|
|
Scheme: http
|
|||
|
|
Forward Hostname: localhost
|
|||
|
|
Forward Port: 3000
|
|||
|
|
|
|||
|
|
SSL: ✓ Force SSL, HTTP/2, HSTS
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Frontend Proxy Host
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
Domain Names: panel.yourdomain.com
|
|||
|
|
Scheme: http
|
|||
|
|
Forward Hostname: localhost
|
|||
|
|
Forward Port: 4173
|
|||
|
|
|
|||
|
|
SSL: ✓ Force SSL, HTTP/2, HSTS
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Advanced (Frontend):**
|
|||
|
|
|
|||
|
|
```nginx
|
|||
|
|
# Proxy backend API calls
|
|||
|
|
location /api {
|
|||
|
|
proxy_pass https://api.yourdomain.com;
|
|||
|
|
proxy_ssl_server_name on;
|
|||
|
|
proxy_set_header Host api.yourdomain.com;
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### CORS Ayarları
|
|||
|
|
|
|||
|
|
İki domain kullanıyorsanız CORS otomatik olarak ayarlanır. Sadece panelden ayarları yapın:
|
|||
|
|
|
|||
|
|
**Panelden Ayarlama (Önerilen):**
|
|||
|
|
|
|||
|
|
1. Giriş yapın → **Ayarlar** → **Genel Ayarlar**
|
|||
|
|
2. **☑ İki Ayrı Domain Kullan** checkbox'ını işaretleyin
|
|||
|
|
3. **Backend Domain**: `https://api.yourdomain.com`
|
|||
|
|
4. **Frontend Domain**: `https://panel.yourdomain.com`
|
|||
|
|
5. **Kaydet** butonuna tıklayın
|
|||
|
|
|
|||
|
|
CORS ayarları otomatik olarak uygulanacaktır.
|
|||
|
|
|
|||
|
|
**Manuel .env Ayarları (Opsiyonel):**
|
|||
|
|
|
|||
|
|
Backend `.env` (varsayılan):
|
|||
|
|
```env
|
|||
|
|
FRONTEND_URL=http://localhost:5173
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
Production'da panel ayarları bu değeri override edecektir.
|
|||
|
|
|
|||
|
|
## ✅ Test ve Doğrulama
|
|||
|
|
|
|||
|
|
### 1. DNS Kontrolü
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# Domain çözümleniyor mu?
|
|||
|
|
nslookup yourdomain.com
|
|||
|
|
|
|||
|
|
# Ping testi
|
|||
|
|
ping yourdomain.com
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. SSL Sertifikası Kontrolü
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# SSL sertifikası geçerli mi?
|
|||
|
|
curl -I https://yourdomain.com
|
|||
|
|
|
|||
|
|
# Detaylı SSL testi
|
|||
|
|
openssl s_client -connect yourdomain.com:443 -servername yourdomain.com
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 3. Endpoint Testleri
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# Frontend erişilebilir mi?
|
|||
|
|
curl https://yourdomain.com
|
|||
|
|
|
|||
|
|
# Backend API erişilebilir mi?
|
|||
|
|
curl https://yourdomain.com/api/health
|
|||
|
|
|
|||
|
|
# Tracking endpoint çalışıyor mu?
|
|||
|
|
curl -I https://yourdomain.com/t/test-token
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 4. Tarayıcı Testleri
|
|||
|
|
|
|||
|
|
1. `https://yourdomain.com` adresine gidin
|
|||
|
|
2. Login sayfası açılmalı
|
|||
|
|
3. Developer Console'da hata olmamalı
|
|||
|
|
4. Network sekmesinde:
|
|||
|
|
- Frontend dosyaları (JS, CSS) yüklenmeli
|
|||
|
|
- API istekleri `/api/*` başarılı olmalı
|
|||
|
|
- CORS hatası olmamalı
|
|||
|
|
|
|||
|
|
## 🐛 Sorun Giderme
|
|||
|
|
|
|||
|
|
### Problem: 502 Bad Gateway
|
|||
|
|
|
|||
|
|
**Çözüm:**
|
|||
|
|
```bash
|
|||
|
|
# Backend çalışıyor mu?
|
|||
|
|
pm2 status
|
|||
|
|
|
|||
|
|
# Port dinleniyor mu?
|
|||
|
|
sudo netstat -tulpn | grep -E ':(3000|4173)'
|
|||
|
|
|
|||
|
|
# Firewall açık mı?
|
|||
|
|
sudo ufw status
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Problem: SSL Sertifikası Alınamıyor
|
|||
|
|
|
|||
|
|
**Çözüm:**
|
|||
|
|
1. DNS kayıtlarının doğru olduğundan emin olun
|
|||
|
|
2. 80 ve 443 portlarının açık olduğunu kontrol edin
|
|||
|
|
3. Domain'in sunucuyu gösterdiğinden emin olun
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# Port 80 ve 443 dinleniyor mu?
|
|||
|
|
sudo netstat -tulpn | grep -E ':(80|443)'
|
|||
|
|
|
|||
|
|
# Firewall kuralları
|
|||
|
|
sudo ufw allow 80/tcp
|
|||
|
|
sudo ufw allow 443/tcp
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Problem: CORS Hatası
|
|||
|
|
|
|||
|
|
**İki subdomain kullanıyorsanız:**
|
|||
|
|
|
|||
|
|
1. Backend `.env` dosyasında `CORS_ORIGIN` ayarlayın
|
|||
|
|
2. Frontend'den API URL'i doğru mu kontrol edin
|
|||
|
|
3. Backend'i yeniden başlatın
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
cd /opt/oltalama/backend
|
|||
|
|
pm2 restart oltalama-backend
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Problem: Tracking Linkleri Çalışmıyor
|
|||
|
|
|
|||
|
|
**Çözüm:**
|
|||
|
|
|
|||
|
|
1. Panelde doğru domain ayarlandığından emin olun
|
|||
|
|
2. `/t/` route'unun proxy'de tanımlı olduğunu kontrol edin
|
|||
|
|
3. Backend loglarını kontrol edin:
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
pm2 logs oltalama-backend --lines 50
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 📊 Performans Optimizasyonu
|
|||
|
|
|
|||
|
|
### NPM Cache Ayarları
|
|||
|
|
|
|||
|
|
**Advanced Nginx Config:**
|
|||
|
|
|
|||
|
|
```nginx
|
|||
|
|
# Static dosyalar için cache
|
|||
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|||
|
|
proxy_pass http://localhost:4173;
|
|||
|
|
expires 1y;
|
|||
|
|
add_header Cache-Control "public, immutable";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# API istekleri için cache yok
|
|||
|
|
location /api {
|
|||
|
|
proxy_pass http://localhost:3000;
|
|||
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Rate Limiting
|
|||
|
|
|
|||
|
|
```nginx
|
|||
|
|
# Rate limit tanımı
|
|||
|
|
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s;
|
|||
|
|
|
|||
|
|
location /api {
|
|||
|
|
limit_req zone=api_limit burst=20 nodelay;
|
|||
|
|
limit_req_status 429;
|
|||
|
|
|
|||
|
|
proxy_pass http://localhost:3000;
|
|||
|
|
# ... diğer ayarlar
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 🔒 Güvenlik İpuçları
|
|||
|
|
|
|||
|
|
1. **NPM Admin Paneli Güvenliği:**
|
|||
|
|
- Port 81'i firewall'dan kapatın (sadece lokal erişim)
|
|||
|
|
- Güçlü şifre kullanın
|
|||
|
|
- 2FA aktif edin (eğer varsa)
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# NPM admin paneline sadece lokal erişim
|
|||
|
|
sudo ufw deny 81/tcp
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
2. **SSL/TLS:**
|
|||
|
|
- Her zaman Let's Encrypt kullanın
|
|||
|
|
- Force SSL aktif edin
|
|||
|
|
- HSTS etkinleştirin
|
|||
|
|
|
|||
|
|
3. **Headers:**
|
|||
|
|
- NPM otomatik güvenlik başlıkları ekler
|
|||
|
|
- Ek başlıklar için Advanced Nginx Config kullanın
|
|||
|
|
|
|||
|
|
## 📝 Özet Karşılaştırma
|
|||
|
|
|
|||
|
|
| Özellik | Tek Domain | İki Subdomain |
|
|||
|
|
|---------|------------|---------------|
|
|||
|
|
| CORS | ✅ Yok | ⚠️ Gerekli |
|
|||
|
|
| SSL | ✅ 1 Sertifika | ⚠️ 2 Sertifika |
|
|||
|
|
| Kurulum | ✅ Kolay | ⚠️ Orta |
|
|||
|
|
| Yönetim | ✅ Basit | ⚠️ Karmaşık |
|
|||
|
|
| DNS | ✅ 1 Kayıt | ⚠️ 2 Kayıt |
|
|||
|
|
| Önerilen | ✅ **Evet** | ⚠️ İhtiyaç varsa |
|
|||
|
|
|
|||
|
|
## 🎯 Sonuç
|
|||
|
|
|
|||
|
|
**Önerimiz:** Tek domain kullanın (`yourdomain.com`)
|
|||
|
|
|
|||
|
|
- Frontend: `yourdomain.com/`
|
|||
|
|
- Backend: `yourdomain.com/api/`
|
|||
|
|
- Tracking: `yourdomain.com/t/`
|
|||
|
|
|
|||
|
|
Bu yapı en kolay ve en sorunsuz çözümdür.
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
**Son Güncelleme:** 2025-11-10
|
|||
|
|
**Versiyon:** 1.0.0
|
|||
|
|
|