feat: implement SSL support with Let's Encrypt and update Nginx configuration

This commit is contained in:
Your Name
2026-03-17 13:03:59 +02:00
parent 47f6b9f669
commit ff5bd19335
5 changed files with 410 additions and 2 deletions

273
fixed-ssl.md Normal file
View File

@@ -0,0 +1,273 @@
سؤالك ممتاز—وده بالضبط الفرق بين **حل “يشتغل وخلاص”** وحل **Production حقيقي**.
خليني أشرح لك الأول **ليه الطريقة الأولى (certbot --nginx) مش مناسبة** عندك، وبعدين أديك **الحل الصحيح الجاهز (Nginx داخل Docker + SSL + Auto renew)** copy/paste.
---
# لماذا `certbot --nginx` مش مناسب عندك؟
أنت عندك:
```text
Nginx شغال داخل Docker (saas-pdf-nginx-1)
```
لكن الأمر:
```bash
certbot --nginx
```
بيفترض إن:
```text
Nginx مثبت على السيرفر (host)
```
📌 النتيجة:
* Certbot حاول يتحكم في Nginx الخارجي
* لكن البورت 80 مستخدم بالفعل بواسطة Docker
* حصل الخطأ: `Address already in use`
---
# هل الحل اللي عملناه “مؤقت”؟
لا 👇
## عندنا 3 مستويات حلول:
### 🥉 حل بدائي
تشغل Certbot خارج Docker → كل مرة توقف Nginx
❌ غير عملي
---
### 🥈 حل متوسط
Certbot standalone + manual config
✔ شغال
❌ لكن renewal مش أوتوماتيك بسهولة
---
### 🥇 الحل الاحترافي (اللي هنطبقه الآن)
```text
Nginx + Certbot داخل Docker
```
✔ Auto renew
✔ scalable
✔ نفس طريقة الشركات الكبيرة
---
# المشاكل لو ما عملتش الحل الصحيح
لو كملت بالحل القديم:
* ❌ SSL هينتهي كل 90 يوم
* ❌ الموقع هيقع فجأة
* ❌ Google هيقلل ترتيبك
* ❌ AdSense ممكن يرفضك
* ❌ صعب التوسعة لاحقًا
---
# الآن الحل الاحترافي (جاهز للتطبيق)
هنعمل 3 حاجات:
```text
1. nginx config احترافي
2. docker-compose فيه SSL
3. auto renew
```
---
# 1⃣ تعديل nginx config
ادخل:
```bash
cd ~/SaaS-PDF/nginx
nano default.conf
```
واستبدل كله بهذا:
```nginx
server {
listen 80;
server_name dociva.io www.dociva.io;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name dociva.io www.dociva.io;
ssl_certificate /etc/letsencrypt/live/dociva.io/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/dociva.io/privkey.pem;
location / {
proxy_pass http://frontend:5173;
}
}
```
---
# 2⃣ تعديل docker-compose.yml
افتح:
```bash
nano docker-compose.yml
```
وابحث عن nginx وعدله:
```yaml
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx:/etc/nginx/conf.d
- ./certbot/www:/var/www/certbot
- ./certbot/conf:/etc/letsencrypt
depends_on:
- frontend
```
---
# 3⃣ إضافة certbot container
في نفس الملف أضف:
```yaml
certbot:
image: certbot/certbot
volumes:
- ./certbot/www:/var/www/certbot
- ./certbot/conf:/etc/letsencrypt
```
---
# 4⃣ تشغيل المشروع
```bash
docker compose down
docker compose up -d
```
---
# 5⃣ إصدار الشهادة (مرة واحدة)
```bash
docker compose run --rm certbot certonly \
--webroot \
--webroot-path=/var/www/certbot \
-d dociva.io -d www.dociva.io \
--email your@email.com \
--agree-tos --no-eff-email
```
---
# 6⃣ إعادة تشغيل Nginx
```bash
docker compose restart nginx
```
---
# 7⃣ اختبار
```text
https://dociva.io
```
🔥 المفروض يشتغل
---
# 8⃣ auto renew (مهم جداً)
أضف cron job:
```bash
crontab -e
```
وأضف:
```bash
0 3 * * * docker compose run --rm certbot renew && docker compose restart nginx
```
---
# النتيجة النهائية
✔ HTTPS شغال
✔ Auto renew
✔ Production ready
✔ مناسب لـ SEO + AdSense
---
# خلاصة بسيطة
| الطريقة | هل مناسبة؟ |
| ---------------- | ---------- |
| certbot --nginx | ❌ لا |
| standalone | ⚠️ مؤقت |
| Docker SSL setup | ✅ الأفضل |
---
# رأيي كمستشار
أنت حالياً وصلت لمستوى:
```text
Junior → Mid-level DevOps 🚀
```
ولو كملت بالشكل ده مشروعك فعلاً ممكن يتحول لمنتج حقيقي.
---
# الخطوة التالية بعد SSL
بعد ما نخلص:
1. Google Search Console
2. Sitemap
3. SEO pages
4. Analytics
---
لو حابب، الخطوة الجاية أعملك:
👉 **إعداد SEO كامل يجلب أول 10,000 زيارة**
بطريقة عملية مش كلام نظري.