アンドロイド

Debian 9で暗号化してApacheを保護する

Debian. ч37. Сборка Debian10.3Dark_Xfce4.14-64bit.

Debian. ч37. Сборка Debian10.3Dark_Xfce4.14-64bit.

目次:

Anonim

Let's Encryptは、Internet Security Research Group(ISRG)によって作成された認証局です。 手動による証明書の作成、検証、インストール、および更新を排除するように設計された完全に自動化されたプロセスにより、無料のSSL証明書を提供します。

Let's Encryptによって発行された証明書は、発行日から90日間有効であり、今日すべての主要なブラウザーによって信頼されています。

このチュートリアルでは、Debian 9でcertbotツールを使用して無料のLet's Encryptを取得するプロセスを説明します。また、新しいSSL証明書を使用してHTTP / 2を有効にするようにApacheを構成する方法も示します。

前提条件

このチュートリアルを続行する前に、次の前提条件を満たしていることを確認してください。

  • sudo特権を持つユーザーとしてログインします。サーバーのパブリックサーバーIPを指すドメイン名を持ちます。 example.com .Apacheをインストールして使用し example.com 。 ドメインのApache仮想ホスト。 作成方法の詳細については、これらの指示に従ってください。

Certbotをインストールする

Certbotは、Let's Encrypt SSL証明書を取得および更新するためのタスクを自動化できる、完全な機能を備えた使いやすいツールです。 certbotパッケージは、デフォルトのDebianリポジトリに含まれています。

パッケージリストを更新し、次のコマンドを使用してcertbotパッケージをインストールします。

sudo apt update sudo apt install certbot

Strong Dh(Diffie-Hellman)グループを生成

Diffie–Hellmanキー交換(DH)は、セキュリティで保護されていない通信チャネルを介して暗号キーを安全に交換する方法です。

2048ビットDHパラメーターの新しいセットを生成するには、次を実行します。

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048 必要に応じて、サイズを最大4096ビットまで変更できますが、その場合、システムのエントロピーによっては生成に30分以上かかる場合があります。

Let's Encrypt SSL証明書の取得

ドメインのSSL証明書を取得するには、 ${webroot-path}/.well-known/acme-challenge ディレクトリに要求されたドメインを検証するための一時ファイルを作成することで機能するWebrootプラグインを使用します。 Let's Encryptサーバーは、一時ファイルに対してHTTP要求を行い、要求されたドメインがcertbotが実行されているサーバーに解決されることを検証します。

より簡単にするために、 .well-known/acme-challenge すべてのHTTPリクエストを単一のディレクトリ /var/lib/letsencrypt ます。

次のコマンドはディレクトリを作成し、Apacheサーバーに対して書き込み可能にします。

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

コードの重複を回避するには、次の2つの構成スニペットを作成します。

/etc/apache2/conf-available/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/apache2/conf-available/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 SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem"

上記のスニペットは、Cipherli.stが推奨するチッパーを使用しており、OCSP Stapling、HTTP Strict Transport Security(HSTS)を有効にし、セキュリティに重点を置いたHTTPヘッダーをほとんど強制しません。

構成ファイルを有効にする前に、次を発行して mod_ssl mod_headers 両方が有効になっていることを確認してください。

sudo a2enmod ssl sudo a2enmod headers

HTTP / 2モジュールを有効にすると、サイトがより高速で堅牢になります。

sudo a2enmod

次のコマンドを実行して、SSL構成ファイルを有効にします。

sudo a2enconf letsencrypt sudo a2enconf ssl-params

変更を有効にするために、Apache構成をリロードします。

sudo systemctl reload apache2

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: IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/example.com/fullchain.pem. Your cert will expire on 2019-01-17. 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 lose your account credentials, you can recover through e-mails sent to [email protected]. - 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:

証明書ファイルを入手したので、次のようにドメイン仮想ホスト構成を編集します。

/etc/apache2/sites-available/example.com.conf

ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration

上記の構成では、HTTPSを強制し、wwwからwww以外のバージョンにリダイレクトしています。 必要に応じて自由に構成を調整できます。

変更を有効にするためにApacheサービスをリロードします。

sudo systemctl reload apache2

https:// を使用してWebサイトを開くと、緑色のロックアイコンが表示されます。

SSL証明書を自動更新しましょう

Let's Encryptの証明書は90日間有効です。 有効期限が切れる前に証明書を自動的に更新するために、certbotパッケージは1日に2回実行されるcronjobを作成し、有効期限の30日前に証明書を自動的に更新します。

証明書が更新されたら、Apacheサービスもリロードする必要があります。 --renew-hook "systemctl reload apache2" /etc/cron.d/certbot ファイルに /etc/cron.d/certbot 、次のようにします。

/etc/cron.d/certbot

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 apache2"

更新プロセスをテストするには、certbot --dry-run スイッチを使用します。

sudo certbot renew --dry-run

エラーがない場合、更新プロセスが成功したことを意味します。

結論

このチュートリアルでは、Let's Encryptクライアントcertbotを使用して、ドメインのSSL証明書を取得しました。 また、コードの重複を避けるためにApacheスニペットを作成し、証明書を使用するようにApacheを構成しました。 チュートリアルの最後で、自動証明書更新用のcronjobをセットアップしました。

apache debian certbot sslを暗号化しましょう

この投稿は、Debian 9シリーズにLAMPスタックをインストールする方法の一部です。

このシリーズの他の投稿:

•Debian 9にApacheをインストールする方法•Debian 9にPHPをインストールする方法•Debian 9にApache仮想ホストを設定する方法•Debian 9にMariaDBをインストールする方法•Debian 9にLet's EncryptでApacheを保護する