هل ترغب في معرفة كيفية تأمين موقع Apache الخاص بك من استخدام Let لتشفير شهادة HTTP المجانية؟ في هذا البرنامج التعليمي ، سوف نعرض لك جميع الخطوات اللازمة لتأمين Apache مع Let's Encrypt on Ubuntu Linux

• إصدار Ubuntu: 18.04

لتوضيح عملية التثبيت ، سنستخدم أحد نطاقاتنا المسماة MINING-POOL.NINJA.

سوف تحتاج إلى تغيير ملفات التكوين واستبدال اسم النطاق الخاص بنا MINING-POOL.NINJA حسب اسم المجال الخاص بك.

قائمة الأجهزة:

يعرض القسم التالي قائمة المعدات المستخدمة لإنشاء هذا البرنامج التعليمي وورد.

كل قطعة من الأجهزة المذكورة أعلاه يمكن العثور عليها في موقع أمازون.

اباتشي دروس ذات صلة:

في هذه الصفحة ، نقدم وصولاً سريعًا إلى قائمة من البرامج التعليمية ذات الصلة بأباتشي.

1. شراء اسم المجال

أولا ، تحتاج إلى الوصول إلى GODADDY وإنشاء حساب.

سيتم استخدام هذا الحساب لشراء مجال DNS.

في مثالنا ، نقوم بشراء النطاق المسمى MINING-POOL.NINJA.

لا تتردد في استخدام أي موقع ويب لشراء مجال DNS.

GoDaddy هو فقط اختياري المفضل.

2. تكوين إدخال DNS

الآن ، تحتاج إلى تكوين سجل DNS يشير إلى خادم الويب الخاص بك Apache.

بعد شراء مجال DNS ، تحتاج إلى إنشاء إدخال DNS يشير إلى عنوان موقع الويب الخاص بك إلى الكمبيوتر الذي يعمل بنظام التشغيل Ubuntu Linux.

في مثالنا ، أنشأنا إدخال DNS يشير إلى المجال MINING-POOL.NINJA إلى عنوان IP 35.163.100.49.

HTTPS DNS Entry

استخدم الأوامر التالية لاختبار تكوين DNS على كمبيوتر يعمل بنظام التشغيل Linux.

# apt-get update
# apt-get install dnsutils
# nslookup mining-pool.ninja

Non-authoritative answer:
Name: mining-pool.ninja
Address: 35.163.100.49

أكد الأمر أعلاه أن النطاق يشير إلى عنوان IP 35.163.100.49.

3. تثبيت خادم الويب أباتشي

تشترط سلطة إصدار شهادات تشفير Let أن يكون لدى المستخدم خادم ويب يعمل بالكامل على Apache.

نحن بحاجة إلى تثبيت خادم الويب Apache وجميع البرامج المطلوبة.

في وحدة تحكم Linux ، استخدم الأوامر التالية لتثبيت الحزم المطلوبة.

# apt-get update
# apt-get install apache2 php7.2 php7.2-mysql libapache2-mod-php7.2
# apt-get install openssl

تمكين Apache mod_rewrite وتعديل ملف apache2.conf.

# a2enmod rewrite
# vi /etc/apache2/apache2.conf

في نهاية الملف ، أضف الأسطر التالية.

<Directory /var/www/html>
AllowOverride All
</Directory>

قم بإنشاء ملف تكوين Apache Virtualhost إلى موقع الويب الخاص بك.

# vi /etc/apache2/sites-available/mining-pool.conf

ضع في اعتبارك أن اسم ملف Virtualhost وموقعه قد لا يكونان نفس اسم موقعي.

على سبيل المثال ، هنا هو محتوى ملفنا:

<VirtualHost *:80>
ServerAdmin nobody@care.com
DocumentRoot /websites/www
ServerName mining-pool.ninja

<Directory /websites/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/logs/error.log
CustomLog /websites/logs/access.log combined
LogLevel error
</VirtualHost>

قم بإنشاء قائمة بالمجلدات المطلوبة.

قم بتعيين إذن الملف الصحيح على كافة المجلدات.

ضع في اعتبارك أن موقع مجلدك قد لا يكون هو نفس موقع المجلد.

# mkdir /websites
# cd /websites
# mkdir www logs
# chown www-data.www-data /websites -R

قم بتمكين تكوين Apache Virtualhost الخاص بك وأعد تشغيل خدمة Apache.

# a2ensite mining-pool.conf
# systemctl reload apache2

4. قم بتكوين شهادة HTTPS المجانية على Apache

في وحدة تحكم Linux ، استخدم الأمر التالي لتثبيت الحزم المطلوبة.

# apt-get install software-properties-common
# add-apt-repository universe
# add-apt-repository ppa:certbot/certbot
# apt-get update
# apt-get install python-certbot-apache

يتطلب البرنامج النصي Certbot من المستخدم أن يكون لديه خادم ويب Apache كامل الوظائف.

لقد انتهينا بالفعل من تركيب وتكوين Apache Virtualhost.

استخدم طلب الأمر التالي وثبت شهادة Apache المجانية HTTPS.

ضع في اعتبارك أن اسم النطاق الخاص بك لا يجب أن يكون هو نفسه اسمك.

# certbot --apache -d mining-pool.ninja

• اضغط على (أ) للموافقة على شروط الخدمة.
• اﺿﻐﻂ ﻋﻠﻰ (Y) ﻟﻤﺸﺎرآﺔ اﻟﺒﺮﻳﺪ اﻹﻟﻜﺘﺮوﻧﻲ اﻟﺨﺎص ﺑﻚ واﺳﺘﻘﺒﺎل اﻟﻨﺸﺮ
• اضغط على (2) لإعادة توجيه موقع الويب الخاص بـ HTTP تلقائيًا إلى إصدارات HTTPS.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): techexpert.tips@gmail.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mining-pool.ninja
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/mining-pool-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/mining-pool-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/mining-pool-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/mining-pool.conf to ssl vhost in /etc/apache2/sites-available/mining-pool-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://mining-pool.ninja

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=mining-pool.ninja
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/mining-pool.ninja/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/mining-pool.ninja/privkey.pem
Your cert will expire on 2019-03-19. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. 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: https://eff.org/donate-le

سيقوم النظام تلقائيًا بطلب الشهادة وتهيئة خادم الويب Apache لإعادة توجيه كل وصول HTTP إلى إصدار HTTPS من موقع الويب الخاص بك.

في هذا المثال ، أنشأ النظام ملف تكوين HTTPS Virtualhost اسمه mining-pool-le-ssl.conf

هنا هو محتوى ملف التكوين HTTPS Virtualhost التعدين- le- ssl.conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin nobody@care.com
DocumentRoot /websites/www
ServerName mining-pool.ninja

<Directory /websites/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/logs/error.log
CustomLog /websites/logs/access.log combined
LogLevel error

SSLCertificateFile /etc/letsencrypt/live/mining-pool.ninja/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mining-pool.ninja/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

يحتوي ملف KEY على المفتاح الخاص لشهادةك ويجب الاحتفاظ به في مكان آمن طوال الوقت.

في ما يلي محتوى ملف KEY: /etc/letsencrypt/live/mining-pool.ninja/privkey.pem

-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCwGYFx4kcQmYC5
gJftnjZhWNVZkIL7wSMTFtFfIY37PNbVNeJ11HoudX8HWout8qXOxBvHE8oUtzrO
/956cCVNsdY+eXZVVwUhjeSRT9wH2vUh3vVw6mi0TRy1KZJGo+hFeUS7zGb0/IwV
MofsEE3rAM1s9RoNOzH6Q/S7OiXFH4OhjbORcv0mBBDjbUgIB+PPoSdCj98yHjZN
vyVEvU9xZLQZxDfFMJr9lNAOR0AIOaALkXaMu1zC5+G1Z2x+W9xSI4JMegiKoHhI
/Xt3A3lCyT81GGc3RrmlighZZVstr0FK4XotcJe5YLsBn1xIukyUrWnJHGRz8MmC
26ShYRLLAgMBAAECggEAdpK19ljGQQcbBczwf67oLuQBxCzqBVomo9PZZpTRZTmx
7h46Pdyz6FR1FB6DrryTqIWjrohEqW42yuq+gvLAK3BzMd3XL99INS+1l6KOJTvp
ksTtvvoXRlAl5FX5iFcVLrJY9ZrMOGlUaXF81BamYHZJ2/OtdvtEy562Str8U52m
GTkgfpWnaLc66T05zViNwiAb5yg0v9Xb9YOEgLY8VdqYppUnJNzYs7utiDGbOjPa
OCZ5oLTl1b9l6sNw7RhhOmq/jPOur4Keg124fyleULi2Uln52waLWeI8fWI/AHmP
UQQkC3athEOKr0f1Zk9ZRxYJq5FYGPTElqQdbltEAQKBgQDiqSp4XM0tfFJwZIkH
ooEcPw+to4T0333K4mipx+YxlELCHvIXW2xIxlejyhgnVIQWX6qS0F7VUGnVuSKz
hB0zfcd89MYcqGyQSEdc9kZB+Twb9Hzd3fTXu7hKjXoz9+UKfcOXfQdILGnDqyG8
zCF//aNocRvxaO9E1cZ+1irlcQKBgQDG5OZUr8kMYI8Tl0GcmWZSFZfMYBYT3CAq
YPHmNQcHhENGz6v9jBZjkeZJBLMRZLlRWjcrWhKbEEHsjZJYiJP4u2n6n57Il9h9
OVqfK7RR3k1r9bMKzhYRnu1FsEPpMKKUrLPDChthxduXEPPZgoKGSYmhLAiYqyPg
USOyZzFt+wKBgQCmfjSgLSrZ2pSD0pWFciz8nqXZml+zr+cq/Jx8+kVw7cML7MdP
uOwVmPwPaAfN/Br6hFM7fKvsbSEQyOlgjA8XH7FFbFeJ/X2hjjY9Zvm8xGMO9cwy
/TM4tL9uo/W77r/jsPXXdRPARD98Z1xk3l1NMvaxZURtU/NN0On5iUABQQKBgGIu
FiER0R3iAF68WLAT7TVx4UgK2nsdO2eQCXkJDhpAyPEIjK8RWu/10oaS4k4guXYW
IYut3+dZpCFAVVCMwvaSlSMZbkk4464VBM3zxgRvxyoW1DXuO2ihWiD/fNZ8opTf
l7EcqR2fjOFKhgUF7qaZYG4GDYxHVuNhSkzDsdvHAoGBAIfDk7fLsG/BYROxJpzN
b1CoG8DE+DKYTWwMWW45rDF0ImbC6H3fg876CeZ3YKGWqt9qkha7gnGGVRRufP15
O7ZEXebZXeDYafXSNcnqSe7FSNtVr1eFlTWmL8OiWQuaqxjs/VogdWfhkEGPISVF
AOM3I6XSGx4NxW2RgYmvQZ4O
-----END PRIVATE KEY-----

قام النظام تلقائيًا بتغيير ملف تكوين Apache Virtualhost الأصلي الخاص بك لإعادة توجيه جميع طلبات HTTP إلى إصدار HTTPS.

هنا هو محتوى ملف التكوين HTTP Virtualhost الذي تم تحديثه والتعدين-pool.conf:

<VirtualHost *:80>
ServerAdmin nobody@care.com
DocumentRoot /websites/www
ServerName mining-pool.ninja

<Directory /websites/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/logs/error.log
CustomLog /websites/logs/access.log combined
LogLevel error
RewriteEngine on
RewriteCond %{SERVER_NAME} =mining-pool.ninja
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost>

5. اختبر موقع Apache HTTPS الخاص بك

لاختبار التثبيت ، افتح المتصفح وأدخل عنوان HTTP لموقعك.

في مثالنا ، تم إدخال عنوان URL التالي في المتصفح:

• http://mining-pool.ninja

بدلاً من إصدار HTTP ، يجب تقديم إصدار HTTPS من موقعك الإلكتروني.

Lets Encrypt Apache

تهانينا ، تستخدم تهيئة Apache الآن شهادة LET'S ENCRYPT المجانية HTTPS.

6. تجديد شهادة Apache HTTPS

يجب أن تكون على علم بأن شهادات Let's Encrypt صالحة لمدة تسعين يومًا فقط.

Apache HTTPS Free Certificate

يقوم النظام بإنشاء مهمة مجدولة لتجديد أي شهادة في غضون ثلاثين يومًا من انتهاء الصلاحية تلقائيًا.

اسم المهمة المجدولة هو certbot ويقع داخل الدليل /etc/cron.d.

في ما يلي محتوى الملف /etc/cron.d/certbot:

# /etc/cron.d/certbot: crontab entries for the certbot package
#
# Upstream recommends attempting renewal twice a day
#
# Eventually, this will be an opportunity to validate certificates
# haven't been revoked, etc. Renewal will only occur if expiration
# is within 30 days.
#
# Important Note! This cronjob will NOT be executed if you are
# running systemd as your init system. If you are running systemd,
# the cronjob.timer function takes precedence over this cronjob. For
# more details, see the systemd.timer manpage, or use systemctl show
# certbot.timer.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

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

استخدم الأمر التالي لمحاكاة عملية تجديد الشهادة.

# certbot renew --dry-run

إذا كان كل شيء يعمل ، سترى الرسائل التالية:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/mining-pool.ninja.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator apache, Installer apache
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for mining-pool.ninja
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/mining-pool.ninja/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/mining-pool.ninja/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.