ذكري المظهر

تأمين اباتشي مع دعونا تشفير على centos 7

Introduction to Amazon Web Services by Leo Zhadanovsky

Introduction to Amazon Web Services by Leo Zhadanovsky

جدول المحتويات:

Anonim

Let's Encrypt هي سلطة إصدار شهادات مجانية وآلية ومفتوحة تم تطويرها بواسطة مجموعة أبحاث أمان الإنترنت (ISRG). الشهادات الصادرة من Let's Encrypt صالحة لمدة 90 يومًا من تاريخ الإصدار وموثوق بها من قبل جميع المتصفحات الرئيسية اليوم.

في هذا البرنامج التعليمي ، سنغطي الخطوات اللازمة لتثبيت شهادة Let's Encrypt SSL المجانية على خادم CentOS 7 يشغل Apache كخادم ويب. سوف نستخدم الأداة المساعدة certbot للحصول على شهادات دعونا تشفير وتجديدها.

المتطلبات الأساسية

تأكد من استيفاء الشروط التالية قبل المتابعة مع هذا البرنامج التعليمي:

  • لديك اسم مجال يشير إلى خادم IP العام الخاص بك. سوف نستخدم example.com يتم تثبيت Apache وتشغيله على الخادم الخاص بك. هل يجب أن يكون مضيف Apache الظاهري للمجال الخاص بك مفتوحًا في الموانئ 80 و 443 في جدار الحماية الخاص بك.

قم بتثبيت الحزم التالية المطلوبة لخادم الويب المشفر SSL:

yum install mod_ssl openssl

تثبيت Certbot

Certbot هي أداة تبسط عملية الحصول على شهادات SSL من Let's Encrypt وتمكين HTTPS تلقائيًا على الخادم الخاص بك.

حزمة certbot قابلة للتثبيت من EPEL. إذا لم يكن مستودع EPEL مثبتًا على نظامك ، فيمكنك تثبيته باستخدام الأمر التالي:

sudo yum install epel-release

بمجرد تمكين مستودع EPEL ، قم بتثبيت حزمة certbot بكتابة:

sudo yum install certbot

إنشاء مجموعة قوية Dh (ديفي هيلمان)

يعد Diffie – Hellman key exchange (DH) طريقة لتبادل آمن لمفاتيح التشفير عبر قناة اتصال غير آمنة. إنشاء مجموعة جديدة من معلمات DH 2048 بت لتعزيز الأمن:

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048 يمكنك تغيير الحجم إلى 4096 بت ، ولكن في هذه الحالة ، قد يستغرق الجيل أكثر من 30 دقيقة اعتمادًا على إنتروبيا النظام.

الحصول على شهادة دعونا تشفير SSL

للحصول على شهادة SSL لنطاقنا ، سنستخدم المكون الإضافي Webroot الذي يعمل عن طريق إنشاء ملف مؤقت للتحقق من صحة النطاق المطلوب في دليل ${webroot-path}/.well-known/acme-challenge . يقوم خادم Let's Encrypt بإرسال طلبات HTTP إلى الملف المؤقت للتحقق من أن المجال المطلوب يحل إلى الخادم حيث يتم تشغيل certbot.

ولجعل الأمر أكثر بساطة ، سنقوم بتعيين جميع طلبات HTTP الخاصة بـ .well-known/acme-challenge إلى دليل واحد ، /var/lib/letsencrypt .

قم بتشغيل الأوامر التالية لإنشاء الدليل وجعله قابلاً للكتابة لخادم Apache:

sudo mkdir -p /var/lib/letsencrypt/.well-known sudo chgrp apache /var/lib/letsencrypt sudo chmod g+s /var/lib/letsencrypt

لتجنب تكرار الشفرة ، قم بإنشاء قصتي التكوين التاليين:

/etc/httpd/conf.d/letsencrypt.conf

Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS /etc/httpd/conf.d/ssl-params.conf

SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 SSLHonorCipherOrder On Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" Header always set X-Frame-Options DENY Header always set X-Content-Type-Options nosniff # Requires Apache >= 2.4 SSLCompression off SSLUseStapling on SSLStaplingCache "shmcb:logs/stapling-cache(150000)" # Requires Apache >= 2.4.11 SSLSessionTickets Off

يستخدم القصاصة أعلاه شرائح التقطيع التي أوصت بها Cipherli.st ، وتمكين OCSP Stapling و HTTP Strict Transport Security (HSTS) وفرض عدد قليل من رؤوس HTTP التي تركز على الأمان.

أعد تحميل تكوين Apache لتصبح التغييرات نافذة المفعول:

sudo systemctl reload

الآن ، يمكننا تشغيل أداة Certbot باستخدام المكون الإضافي webroot والحصول على ملفات شهادة SSL عن طريق الكتابة:

sudo certbot certonly --agree-tos --email [email protected] --webroot -w /var/lib/letsencrypt/ -d example.com -d www.example.com

إذا تم الحصول على شهادة SSL بنجاح ، فسوف يقوم certbot بطباعة الرسالة التالية:

IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2018-12-07. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF:

يأتي CentOS 7 مع الإصدار 2.4.6 من Apache ، والذي لا يتضمن توجيه SSLOpenSSLConfCmd . لا يتوفر هذا التوجيه إلا في الإصدار 2.4.8 من Apache لاحقًا ، ويتم استخدامه لتهيئة معلمات OpenSSL مثل تبادل مفاتيح Diffie-Hellman (DH).

سيتعين علينا إنشاء ملف مدمج جديد باستخدام شهادة Let's Encrypt SSL وملف DH الذي تم إنشاؤه. للقيام بذلك ، اكتب:

cat /etc/letsencrypt/live/example.com/cert.pem /etc/ssl/certs/dhparam.pem >/etc/letsencrypt/live/example.com/cert.dh.pem

الآن بعد إعداد كل شيء ، قم بتعديل تكوين المضيف الظاهري لنطاقك كما يلي:

/etc/httpd/conf.d/example.com.conf

ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration

من خلال التكوين أعلاه ، فإننا نلزم HTTPS ونعيد التوجيه من www إلى إصدار غير www. تتردد في ضبط التكوين وفقًا لاحتياجاتك.

أعد تشغيل خدمة Apache لتصبح التغييرات نافذة المفعول:

sudo systemctl restart

يمكنك الآن فتح موقع الويب الخاص بك باستخدام https:// وستلاحظ رمز القفل الأخضر.

التجديد التلقائي دعونا تشفير شهادة SSL

شهادات تشفير دعونا صالحة لمدة 90 يوما. لتجديد الشهادات تلقائيًا قبل انتهاء صلاحيتها ، سنقوم بإنشاء cronjob سيتم تشغيله مرتين في اليوم وتجديد أي شهادة تلقائيًا قبل 30 يومًا من انتهاء صلاحيتها.

قم بتشغيل الأمر crontab لإنشاء cronjob جديد لتجديد الشهادة وإنشاء ملف مدمج جديد بما في ذلك مفتاح DH وإعادة تشغيل apache:

sudo crontab -e

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew --renew-hook "systemctl reload

أحفظ وأغلق الملف.

لاختبار عملية التجديد ، يمكنك استخدام الأمر certbot متبوعًا --dry-run :

sudo certbot renew --dry-run

إذا لم تكن هناك أخطاء ، فهذا يعني أن عملية التجديد كانت ناجحة.

استنتاج

في هذا البرنامج التعليمي ، قمت باستخدام certbot العميل Let's Encrypt لتنزيل شهادات SSL لنطاقك. لقد أنشأت أيضًا قصاصات Apache لتجنب تكرار التعليمات البرمجية وتكوين Apache لاستخدام الشهادات. في نهاية البرنامج التعليمي ، قمت بإعداد cronjob لتجديد الشهادة تلقائيًا.

اباتشي centos دعونا تشفير certbot SSL

هذا المنشور جزء من Install LAMP Stack على سلسلة CentOS 7.

وظائف أخرى في هذه السلسلة:

• كيفية تثبيت Apache على CentOS 7 • تثبيت MySQL على CentOS 7 • كيفية إعداد مضيفات Apache الافتراضية على CentOS 7 • تأمين Apache مع Let's Encrypt على CentOS 7