Установка и настройка CentOS в VirtualBox
目次:
Let's Encryptは、Internet Security Research Group(ISRG)によって開発された、無料の自動化されたオープンな認証局です。 Let's Encryptによって発行された証明書は、発行日から90日間有効であり、今日すべての主要なブラウザーによって信頼されています。
このチュートリアルでは、ApacheをWebサーバーとして実行しているCentOS 7サーバーに無料のLet's Encrypt SSL証明書をインストールするために必要な手順を説明します。 Let's Encrypt証明書を取得して更新するには、certbotユーティリティを使用します。
前提条件
このチュートリアルを続行する前に、次の前提条件を満たしていることを確認してください。
- パブリックサーバーのIPを指すドメイン名を持っています。
example.com
を使用しexample.com
。Apacheがサーバーにインストールされ、実行されています。ドメインのApache仮想ホストを使用します。ポート80および443はファイアウォールで開いています。
SSL暗号化Webサーバーに必要な次のパッケージをインストールします。
Certbotをインストールする
Certbotは、Let's EncryptからSSL証明書を取得し、サーバーでHTTPSを自動有効化するプロセスを簡素化するツールです。
certbotパッケージは、EPELからインストールできます。 EPELリポジトリがシステムにインストールされていない場合、次のコマンドを使用してインストールできます。
sudo yum install epel-release
EPELリポジトリが有効になったら、次を入力して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 apache /var/lib/letsencrypt
sudo chmod g+s /var/lib/letsencrypt
コードの重複を回避するには、次の2つの構成スニペットを作成します。
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
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
これで、webrootプラグインを使用してCertbotツールを実行し、次のように入力して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には、
SSLOpenSSLConfCmd
ディレクティブを含まないApacheバージョン2.4.6が
SSLOpenSSLConfCmd
しています。 このディレクティブは、Apache 2.4.8以降でのみ使用でき、Diffie–Hellman鍵交換(DH)などのOpenSSLパラメーターの構成に使用されます。
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://
を使用してWebサイトを開くことができ、緑色のロックアイコンが表示されます。
SSL証明書を自動更新しましょう
Let's Encryptの証明書は90日間有効です。 有効期限が切れる前に証明書を自動的に更新するには、1日に2回実行される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
エラーがない場合、更新プロセスが成功したことを意味します。
結論
このチュートリアルでは、Let's Encryptクライアントcertbotを使用して、ドメインのSSL証明書をダウンロードしました。 また、コードの重複を避けるためにApacheスニペットを作成し、証明書を使用するようにApacheを構成しました。 チュートリアルの最後で、証明書の自動更新のためのcronjobをセットアップしました。
Apache CentOS certbot sslを暗号化しましょうこの投稿は、CentOS 7シリーズへのLAMPスタックのインストールの一部です。
このシリーズの他の投稿:
•CentOS 7にApacheをインストールする方法•CentOS 7にMySQLをインストールする•CentOS 7にApache仮想ホストを設定する方法•CentOS 7でLet's Encryptを使用してApacheを保護するCentOS 7でワニスを使用するようにmagento 2を構成する

ページの速度は、オンラインストアの成功に不可欠です。 このチュートリアルでは、Magento 2を設定してVarnishをフルページキャッシュソリューションとして使用する手順を説明します。
CentOS 7でユーザーを追加および削除する方法

ユーザーを追加および削除する方法を知ることは、Linuxユーザーが知っておくべき基本的なスキルの1つです。 このチュートリアルでは、CentOS 7システムでユーザーを追加および削除する方法を説明します。
CentOS 7でスワップスペースを追加する方法

スワップは、物理RAMメモリの容量がいっぱいになったときに使用されるディスク上のスペースです。 このチュートリアルでは、CentOS 7システムにスワップファイルを追加する方法について説明します。