GNU/Linux >> Linux の 問題 >  >> Cent OS

CentOS7にApacheでLet'sEncryptをインストールする方法

このチュートリアルでは、Let’sEncryptクライアントをCentOS7 VPSにインストールし、ドメインのSSL証明書を発行する方法を示します。

SSL暗号化によってWebサイトのセキュリティを向上させると、Webサイトに対する訪問者の信頼を高めることができます。以前は、WebサイトでSSL暗号化を設定することは複雑な作業でした。ただし、Let’s Encryptは無料のオープンソース認証局(CA)であり、シンプルな自動コマンドを使用して証明書を取得およびインストールできます。それらのおかげで、暗号化の設定とサイトのセキュリティの強化がはるかに簡単になりました。 Let’s Encryptは、ドメインに有効なSSL証明書を無料で提供し、本番/商用目的でも使用できます。

インストールから始めましょう。簡単なインストールで、それほど時間はかかりません。

前提条件
  • このチュートリアルでは、CentOS7VPSを使用します。
  • 完全なSSHルートアクセスまたはsudo権限を持つユーザーも必要です。
  • サーバーのIPアドレスを指す有効なドメイン名。このチュートリアルでは、domain.comを使用します 。

ステップ1:SSH経由で接続してOSを更新する

次のコマンドを使用して、rootユーザーとしてSSH経由でサーバーに接続します。

ssh root@IP_ADDRESS -p PORT_NUMBER

「IP_ADDRESS」と「PORT_NUMBER」をサーバーのそれぞれのIPアドレスとSSHポート番号に置き換えることを忘れないでください。

インストールを開始する前に、OSパッケージを最新バージョンに更新する必要があります。簡単に実行でき、数分もかかりません。

これを行うには、次のコマンドを実行します。

yum update

更新が完了したら、次のステップに進むことができます。

ステップ2:LAMPスタックをインストールする

サーバーにLAMPスタックをインストールする必要があります。 Linux(すでに持っている)、Apache、MySQL、およびPHPで構成されています。次のコマンドを実行してインストールできます:

yum install httpd mariadb-server php php-cli php-common

すべてのパッケージがインストールされたら、ApacheおよびMariaDBサービスを開始します。

systemctl start httpd
systemctl start mariadb

次のコマンドを使用して、サーバーの起動時に起動できるようにします。

systemctl enable httpd
systemctl enable mariadb

ステップ3:Apacheを構成する

新しいApache構成ファイルを作成する必要があります。次のコマンドで作成できます:

nano /etc/httpd/conf.d/domain.com.conf

次の行を追加します:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/var/www/html"
    DirectoryIndex index.html
    ServerName domain.com
    ErrorLog "/var/log/httpd/domain.com.error_log"
    CustomLog "/var/log/httpd/domain.com.access_log" common
</VirtualHost>

ファイルを保存して閉じます。

次に、index.htmlを作成します 次のコマンドを使用して、テスト用のファイルを作成します。

nano /var/www/html/index.html

次の行を追加します:

<html>
Test - Welcome to The Apache Web Server.
</html>

ファイルを保存し、「/ var / www / html / index.html」ファイルの所有者をApacheユーザーに変更して、Apacheがファイルを読み取れるようにします。

chown -R apache:apache /var/www/html/index.html

domain.comを変更することを忘れないでください 実際のドメイン名を使用します。
Apacheがインストールされたので、続行してcertbotをインストールできます。 。

ステップ4:Certbotをインストールする

Certbotをインストールし、mod_sslを有効にする必要があります サーバー上のApacheモジュール。 Certbotは、証明書の取得とそれらを使用するためのWebサービスの構成を自動化することにより、サーバー管理を簡素化するシンプルで使いやすいツールです。

デフォルトでは、CertbotパッケージはCentOS7のデフォルトOSリポジトリでは使用できません。 EPELリポジトリを有効にしてから、Certbotをインストールする必要があります。

EPELリポジトリを追加するには、次のコマンドを実行します。

yum install epel-release

有効にしたら、次のコマンドを使用して必要なすべてのパッケージをインストールします。

yum install certbot python2-certbot-apache mod_ssl

インストールしたら、次のステップに進むことができます。

ステップ5:ドメインのSSLを取得してインストールする

Certbotがインストールされたので、Certbotを使用してドメインのSSL証明書を取得してインストールできます。

次のコマンドを実行して、ドメインのSSL証明書を取得してインストールします。

certbot --apache -d domain.com

サーバーでホストされている複数のドメインとサブドメインに「-d」フラグを付けて単一の証明書をインストールすることもできます(例:

)。
certbot --apache -d domain.com -d www.domain.com -d domain2.com -d test.domain2.com

メールアドレスを入力し、利用規約に同意するよう求められます。

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): [email protected]
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: N
Starting new HTTPS connection (1): supporters.eff.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for domain.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/httpd/conf.d/domain.com-le-ssl.conf
Deploying Certificate to VirtualHost /etc/httpd/conf.d/domain.com-le-ssl.conf

Yと入力して[Enter]キーを押すと、次の出力が表示されます。

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

ここで、続行するにはいずれかのオプションを選択する必要があります。オプション1を選択すると、SSL証明書のみがダウンロードされるため、SSL証明書を使用するにはApacheを手動で構成する必要があります。オプション2を選択すると、SSL証明書を使用するようにApacheが自動的にダウンロードおよび構成されます。この場合、オプション2を選択し、[Enter]キーを押します。インストールが正常に完了すると、次のようなメッセージが表示されます。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://domain.com
が正常に有効になりました
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/domain.com-0001/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/domain.com-0001/privkey.pem
Your cert will expire on 2019-10-22. 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

生成された証明書ファイルは、/etc/letsencrypt/live/domain.comで入手できます。 ディレクトリ。次のコマンドを使用して、新しく作成されたSSL証明書を確認できます。

ls /etc/letsencrypt/live/domain.com/

次の出力が表示されます。

cert.pem chain.pem fullchain.pem privkey.pem

ステップ6:SSL証明書を確認する

Webブラウザーを開き、URL https://domain.comを入力します 。 ChromeでSSL証明書を確認するには、https://domain.comのアドレスバーにある南京錠のアイコンをクリックし、ポップアップボックスから[証明書]プロンプトの下の[有効]をクリックします。

ステップ7:自動更新を設定する

デフォルトでは、Let’s Encrypt証明書は90日間有効であるため、有効期限が切れる前に証明書を更新することをお勧めします。理想的には、更新プロセスを自動化して、証明書を定期的にチェックして更新するのが最善です。

次のコマンドを使用して、更新プロセスを手動でテストできます。

certbot renew --dry-run

上記のコマンドは、現在インストールされている証明書を自動的にチェックし、有効期限から30日以内の場合は更新を試みます。

cronjobを追加して、上記のコマンドを1日2回自動的に実行することもできます。

これを行うには、次のコマンドを使用してcrontabを編集します。

crontab -e

次の行を追加します:

* */12 * * * root /usr/bin/certbot renew >/dev/null 2>&1

ファイルを保存して閉じます。

おめでとう!これで、CentOS 7VPSにLet’s EncryptwithApacheが正常にインストールおよび構成されました。

もちろん、マネージドVPSホスティングプランのいずれかを使用している場合は、CentOS 7にLet’s Encryptをインストールする必要はありません。その場合は、専門のLinux管理者にCentOS 7 VPSにLet’sEncryptをインストールするよう依頼するだけです。 24時間年中無休でご利用いただけます。リクエストはすぐに処理されます。

PS Let’sEncryptをCentOS7にインストールする方法に関するこの投稿が気に入った場合 、または役に立った場合は、共有ボタンを使用してソーシャルネットワークで友達と共有するか、下に返信を残してください。ありがとう。


Cent OS
  1. Let’sEncryptをCentos8にインストールする

  2. CentOS8にApacheCassandraをインストールする方法

  3. Debian 11 に Let’s Encrypt SSL を Apache でインストールする方法

  1. CentOS7にApacheをインストールする方法

  2. CentOS7でLetsEncryptを使用してApacheを保護する

  3. CentOS7にApacheMavenをインストールする方法

  1. CentOS7にApacheを使用してWordPressをインストールする方法

  2. CentOS7にApacheCassandraをインストールする方法

  3. CentOS8にApacheをインストールする方法