راهنمای بهروزرسانی SSL برای BigBlueButton + HAProxy
راهنمای بهروزرسانی SSL برای BigBlueButton + HAProxy
=====================================================
دامنه:
site.com
معماری SSL این سرور
===================
در این سرور SSL روی HAProxy terminate میشود، نه روی Nginx.
Certificate جدید Let's Encrypt:
/etc/letsencrypt/live/site.com/fullchain.pem
Private Key:
/etc/letsencrypt/live/site.com/privkey.pem
Certificate مورد استفاده HAProxy:
/etc/haproxy/certbundle.pem
کانفیگ HAProxy:
/etc/haproxy/haproxy.cfg
کانفیگ Nginx مربوط به BigBlueButton:
/etc/nginx/sites-enabled/bigbluebutton
HAProxy روی پورت 443 فعال است.
Nginx روی پورتهای داخلی 81 و 82 کار میکند.
=====================================================
بررسی Certificate
=====================================================
بررسی Certificate جدید Let's Encrypt:
sudo openssl x509 -in /etc/letsencrypt/live/site.com/fullchain.pem -noout -subject -issuer -dates
بررسی Certificate فعلی HAProxy:
sudo openssl x509 -in /etc/haproxy/certbundle.pem -noout -subject -issuer -dates
اگر Certificate داخل certbundle.pem قدیمی یا منقضی بود، مراحل زیر را انجام بده.
=====================================================
مرحله 1 - Backup
=====================================================
قبل از هر تغییری از Certificate فعلی HAProxy بکاپ بگیر:
sudo cp -a /etc/haproxy/certbundle.pem /etc/haproxy/certbundle.pem.backup-$(date +%Y%m%d-%H%M%S)
=====================================================
مرحله 2 - ساخت Bundle جدید
=====================================================
HAProxy به یک فایل PEM نیاز دارد که شامل Private Key و Certificate Chain باشد.
دستور:
sudo sh -c 'cat /etc/letsencrypt/live/site.com/privkey.pem /etc/letsencrypt/live/site.com/fullchain.pem > /etc/haproxy/certbundle.pem'
=====================================================
مرحله 3 - تنظیم Permission
=====================================================
sudo chown root:root /etc/haproxy/certbundle.pem
sudo chmod 600 /etc/haproxy/certbundle.pem
=====================================================
مرحله 4 - بررسی Certificate جدید
=====================================================
sudo openssl x509 -in /etc/haproxy/certbundle.pem -noout -subject -issuer -dates
تاریخ notAfter باید تاریخ انقضای Certificate جدید باشد.
=====================================================
مرحله 5 - تست کانفیگ HAProxy
=====================================================
قبل از Reload حتماً کانفیگ را تست کن:
sudo haproxy -c -f /etc/haproxy/haproxy.cfg
اگر Configuration معتبر بود، ادامه بده.
اگر خطا داد، HAProxy را Reload نکن.
=====================================================
مرحله 6 - Reload کردن HAProxy
=====================================================
sudo systemctl reload haproxy
سپس وضعیت را بررسی کن:
sudo systemctl status haproxy --no-pager
باید ببینی:
Active: active (running)
=====================================================
مرحله 7 - تست Certificate واقعی سایت
=====================================================
این مهمترین تست نهایی است:
echo | openssl s_client -connect site.com:443 -servername site.com 2>/dev/null | openssl x509 -noout -subject -issuer -dates
تاریخ notAfter باید مربوط به Certificate جدید باشد.
=====================================================
اگر سایت بعد از Reload بالا نیامد
=====================================================
وضعیت HAProxy:
sudo systemctl status haproxy --no-pager
لاگ HAProxy:
sudo journalctl -u haproxy -n 100 --no-pager
تست کانفیگ:
sudo haproxy -c -f /etc/haproxy/haproxy.cfg
بررسی پورتها:
sudo ss -lntp | grep -E ':443|:81|:82'
بررسی Nginx:
curl -v http://127.0.0.1:81/
=====================================================
نکته مهم برای تمدیدهای آینده
=====================================================
در این سرور، تمدید Certificate در Let's Encrypt بهتنهایی کافی نیست.
Let's Encrypt Certificate را در این مسیر قرار میدهد:
/etc/letsencrypt/live/site.com/
اما HAProxy از این فایل استفاده میکند:
/etc/haproxy/certbundle.pem
بنابراین بعد از هر تمدید Certificate باید:
1. certbundle.pem را با Certificate جدید بسازی.
2. Permission را تنظیم کنی.
3. کانفیگ HAProxy را تست کنی.
4. HAProxy را Reload کنی.
5. Certificate واقعی سایت را تست کنی.
=====================================================
دستورهای اصلی برای دفعات بعد
=====================================================
Backup:
sudo cp -a /etc/haproxy/certbundle.pem /etc/haproxy/certbundle.pem.backup-$(date +%Y%m%d-%H%M%S)
ساخت Bundle:
sudo sh -c 'cat /etc/letsencrypt/live/site.com/privkey.pem /etc/letsencrypt/live/site.com/fullchain.pem > /etc/haproxy/certbundle.pem'
Permission:
sudo chown root:root /etc/haproxy/certbundle.pem
sudo chmod 600 /etc/haproxy/certbundle.pem
تست:
sudo haproxy -c -f /etc/haproxy/haproxy.cfg
Reload:
sudo systemctl reload haproxy
تست نهایی:
echo | openssl s_client -connect site.com:443 -servername site.com 2>/dev/null | openssl x509 -noout -subject -issuer -dates
=====================================================
پیشنهاد برای آینده
=====================================================
بهتر است این فرآیند را با Certbot deploy-hook خودکار کنیم.
در آن حالت هر بار Certificate با موفقیت تمدید شود، سیستم بهصورت خودکار:
- certbundle.pem را بهروز میکند
- Permission را تنظیم میکند
- کانفیگ HAProxy را تست میکند
- HAProxy را Reload میکند
با این کار دیگر لازم نیست هر 6 ماه این کارها را دستی انجام بدهی.


