GNU/Linux >> Linux の 問題 >  >> Panels >> Panels

Apacheを使用してUbuntu20.04にLet’sEncryptをインストールする方法

この記事では、Let’sEncryptクライアントをUbuntu20.04 VPSにインストールし、ドメインのSSL証明書を発行し、ApacheWebサーバーで構成する方法を説明します。

Let’s Encryptは、誰でも簡単で自動化されたコマンドで無料のSSL証明書を取得できる認証局(CA)です。このチュートリアルでは、certbotというツールを使用します 、これはインターネット全体を暗号化するためのEFFの取り組みの公式な部分です。この便利なツールのおかげで、SSL証明書を設定して、Webサイトの訪問者を保護し、Webサイトのセキュリティを向上させることがこれまでになく簡単になりました。 Let’s Encryptが提供するすべてのSSL証明書は、コストや料金なしで本番/商用目的で使用できます。インストールとセットアップから始めましょう。

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

前提条件

  • このチュートリアルでは、Ubuntu20.04VPSを使用します。
  • sudo権限または完全なSSHルートアクセス権を持つユーザーが必要です。すべてのVPSにはrootアクセスが付属しています。
  • サーバーのIPアドレスを指す有効なドメイン名。このチュートリアルでは、domain.comを使用します 例として。

1。サーバーに接続する

始める前に、rootユーザーとしてSSH経由でサーバーに接続する必要があります。これを行うには、次のコマンドを使用します。

ssh root@IP_ADDRESS -p PORT_NUMBER

もちろん、IP_ADDRESSを置き換える必要があります およびPORT_NUMBER 実際のサーバーのIPアドレスとSSHポート番号を使用します。

ログインしたら、次のコマンドを実行して、サーバーが最新であることを確認します。

sudo apt update
sudo apt upgrade

2。 Apache2Webサーバーをインストールします

この記事では、最も人気のあるWebサーバーの1つを使用することにしました。無料のLet’s Encrypt SSL証明書をインストールするWebサーバーが必要なため、Apache2をインストールします。 WebページなしでSSL証明書を持っていても意味がありません。最高の無料のLet’sEncryptの代替案について調べてください。

次のコマンドを実行して、Apache2をインストールします。

sudo apt install apache2

サーバーにApache2をインストールすると、以下のコマンドを使用してサービスを開始、停止、および有効化できるようになります。サーバーが再起動するたびにApacheが自動的に起動できるように、有効にすることをお勧めします。

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

Apache2が正しくインストールされていることを確認するには、お好みのWebブラウザーを開いて、サーバーのIPアドレスまたはドメイン(サーバーを指していると想定)を入力すると、Apache2Ubuntuのデフォルトページが表示されます。

3。 Apache仮想ホストを構成する

サーバーにApacheがインストールされたので、続行して、使用するドメインの仮想ホストを作成する方法を示します。エディターとしてnanoを使用しますが、nanoを使用したくない場合は、任意のエディターを使用して、domain.com.confという新しい構成ファイルを作成できます。 。

sudo nano /etc/apache2/sites-available/domain.com.conf

次に、構成を下からファイルに貼り付け、出現するすべてのdomain.comを置き換えます。 実際のドメイン名を使用します。

<VirtualHost *:80>

DocumentRoot /var/www/html/domain.com
ServerName domain.com
ServerAlias www.domain.com

<Directory /var/www/html/domain.com/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

ファイルの編集が終了したら、保存して閉じます。

仮想ホストを構成したら、次のコマンドを実行して仮想ホストを有効にできます。

次のコマンドでデフォルトのプレインストールされた仮想ホストを無効にします:

sudo a2dissite 000-default

次に、domain.comを有効にします 仮想ホスト:

sudo a2ensite domain.com.conf

また、modがrewriteであることを確認する必要があります 有効になっている:

sudo a2enmod rewrite

Apacheを再起動して、変更を有効にします。

sudo systemctl restart apache2.service

4。 Certbotをインストールする

前述のように、Certbotを使用して、Let’sEncryptから無料のSSL証明書を取得できるようにします。この便利なツールをインストールするには、universeを有効にする必要があります リポジトリ:

sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update

マシンのコマンドラインでこのコマンドを実行して、Certbotをインストールします。

sudo apt install certbot python3-certbot-apache

5。無料のLet'sEncryptSSL証明書を生成する

Certbotを使用してSSL証明書を取得する方法はたくさんあります。 Apacheプラグインを使用します。このプラグインは、Apacheの仮想ホストの再構成を処理し、新しい構成を再ロードします。次のコマンドを実行して、プラグインを使用できます。

sudo certbot --apache

このスクリプトを使用して、一連の質問に回答し、電子メールアドレスを提供する必要があります。最初のステップでは、有効なメールアドレスを入力する必要があります。ウェブサイトの証明書に関する通知とセキュリティ通知には、メールアドレスが必要です:

Output:
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]

次のステップは、Let’sEncryptの利用規約に同意することを確認することです。確認したい場合は、Aと入力して[ENTER]を押してください:

Output:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

提供された電子メールアドレスをEFF(Electronic Frontier Foundation)と共有してニュースやその他の情報を受信する場合は、Yと入力できます。このタイプの電子メールを受信したくない場合は、Nと入力して、次の方法で回答を送信できます。 [ENTER]と入力します。

Output:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

次に、HTTPSをアクティブ化するドメインを選択する必要があります。コマンドプロンプトにリストされているドメインとサブドメインは、Apache仮想ホスト構成から自動的に取得されます。数字をカンマやスペースで区切って入力するか、すべてのドメインまたはサブドメインでHTTPSを有効にする場合は、プロンプトを空白のままにすることができます。いずれの場合も、[ENTER]を押して次のステップに進みます。

Output:
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: domain.com
2: www.domain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):

出力は次のようになります:

Output:
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for domain.com
http-01 challenge for www.domain.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/domain.com-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/domain.com-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/domain.com-le-ssl.conf

Certbotは、有効にできるオプションとしてHTTPSリダイレクトを提供します。このステップでは、スクリプトにより、HTTPトラフィック全体をHTTPSにリダイレクトするか、現在の構成を維持するかを選択するように求められます。リダイレクトしない場合は1を選択し、リダイレクトを有効にする場合は2を選択して、[ENTER]を押します。

Output:
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

よくやった。これで、SSL証明書がインストールされ、Apache構成にロードされます。次のような出力が表示されます。

Output:
Redirecting vhost in /etc/apache2/sites-enabled/domain.com.conf to ssl vhost in /etc/apache2/sites-available/domain.com-le-ssl.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://domain.com

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

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/domain.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/domain.com/privkey.pem
Your cert will expire on 2021-09-09. 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"
- 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.
- 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

新しいSSL証明書が正しく設定されていることを確認するには、https://domain.com/にアクセスしてください。 Webブラウザで、URLバーの緑色の鍵のアイコンを確認します。外部のWebサイトまたはツールを使用して、SSL証明書が正しくインストールされているかどうかを確認することもできます。

6。 Certbotの自動更新の確認

Let’s Encryptが提供するSSL証明書は、90日間のみ有効です。インストールしたCertbotは、有効期限から30日以内のSSL証明書の更新を処理するcronジョブを設定します。このサービスのステータスを確認するには、次のコマンドを実行します。

sudo systemctl status certbot.timer
Output:
● certbot.timer - Run certbot twice daily
Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Thu 2021-06-11 11:33:00 UTC; 1h 37min ago
Trigger: Thu 2021-06-11 15:52:01 UTC; 2h 41min left
Triggers: ● certbot.service

または、次のコマンドですべてのタイマーを一覧表示できます:

sudo systemctl list-timers

次のコマンドを実行して、証明書の自動更新をテストできます。

sudo certbot renew --dry-run

また、SSL証明書を更新するコマンドは、次のいずれかの場所にあります。

/etc/crontab/
/etc/cron.*/*

おめでとう!ドメインに無料のLet’sEncryptSSL証明書が正常にインストールされました。

この記事では、Apache2 WebサーバーとCertbotをインストールする方法、およびApache仮想ホストを作成する方法、そしてもちろん、ドメインにSSL証明書をインストールする方法を示しました。これで、Webサイトは安全になり、その状態を維持するために自動的に更新されます。

もちろん、マネージドUbuntu Hostingをご利用の場合は、ドメインのLet’s Encrypt SSL証明書を自分でインストールする必要はありません。管理者に聞いて、くつろいでリラックスしてください。私たちの管理者は、Ubuntu 20.04 VPSにLet’s Encrypt SSL証明書をすぐにインストールし、私たちが実行できる多くの便利な最適化を提供します。

Apacheを使用してUbuntu20.04にLet’s Encryptをインストールする方法に関するこの投稿が気に入った場合は、下の共有ボタンを使用してソーシャルネットワーク上の友達と共有するか、コメントセクションにコメントを残してください。ありがとう。


Panels
  1. Ubuntu14.04にNginxでElggをインストールする方法

  2. Nginxを使用してUbuntu18.04にLet'sEncryptSSLをインストールする方法

  3. Ubuntu18.04にNginxでJoomlaをインストールする方法

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

  2. Ubuntu20.04にApacheをインストールする方法

  3. Ubuntu18.04にApacheを使用してJoomlaをインストールする方法

  1. Apacheを使用してUbuntu20.04にPrestaShopをインストールする方法

  2. Ubuntu20.04にLetsEncryptを使用してSonarQubeをインストールする方法

  3. Apacheを使用してUbuntu20.04にNextCloudをインストールする方法