このチュートリアルでは、Let's Encrypt SSL with NginxをCentOS7にインストールする方法を紹介します。知らない人のために、LetsEncryptは無料のオープン認証局(CA)です。これは、Webサイトやその他のサービスに無料の証明書を提供します。このサービスは、Electronic Frontier Foundation、Mozilla、Cisco Systems、およびAkamaiによってサポートされています。残念ながら、LetsEncrypt.orgの証明書の有効期間は現在3か月です。つまり、更新する必要があります。今のところ、四半期ごとに証明書を発行します。
この記事は、少なくともLinuxの基本的な知識があり、シェルの使用方法を知っていること、そして最も重要なこととして、サイトを独自のVPSでホストしていることを前提としています。インストールは非常に簡単で、ルートアカウントで実行されていますが、そうでない場合は、' sudo
を追加する必要があります。 ルート権限を取得するコマンドに‘。 CentOS7サーバーにNginxでSSLを暗号化するステップバイステップのインストールを紹介します。
前提条件
- 次のオペレーティングシステムのいずれかを実行しているサーバー:CentOS7。
- 潜在的な問題を防ぐために、OSの新規インストールを使用することをお勧めします。
- サーバーへのSSHアクセス(またはデスクトップを使用している場合はターミナルを開く)
非rootsudoユーザー
またはrootユーザー
へのアクセス 。非rootsudoユーザー
として行動することをお勧めします ただし、ルートとして機能するときに注意しないと、システムに害を及ぼす可能性があるためです。
CentOS7にNginxでSSLを暗号化してインストール
ステップ1.まず、システムが最新であることを確認することから始めましょう。
yum clean all yum -y update
ステップ2.CentOS7にLet'sEncryptSSLをインストールします。
CentOS 7では、EPELリポジトリにCertbotがあります。有効にすると、必要なものをインストールするだけです。
yum install epel-release yum install certbot
Nginxもインストールして実行する必要があります。もちろん、以前に構成したWebホストに証明書を追加する場合、これはすでにインストールされています:
>yum install nginx systemctl start nginx
CentOS LinuxにSSLを暗号化するための最初のステップは、Nginx仮想ホスト構成内に単純な構成を追加することです。vhost構成に次の行を追加します。
location ~ /.well-known { allow all; }
保存して終了し、変更を適用します:
nginx -t systemctl restart nginx
Certbotで証明書を取得する:
以下のようにコマンドを実行し、「idroot.us」を実際のドメイン名と /var/www/idroot.us
> 実際のWebルートパスを使用:
certbot certonly -a webroot --webroot-path=/var/www/idroot.us -d idroot.us -d www.idroot.us
結果:
[[email protected]:~]certbot certonly -a webroot --webroot-path=/var/www/idroot.us -d idroot.us -d www.idroot.us Saving debug log to /var/log/letsencrypt/letsencrypt.log Obtaining a new certificate Performing the following challenges: http-01 challenge for idroot.us Using the webroot path /var/www/html for all unmatched domains. Waiting for verification... Cleaning up challenges Generating key (2048 bits): /etc/letsencrypt/keys/0001_key-certbot.pem Creating CSR: /etc/letsencrypt/csr/0001_csr-certbot.pem IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/idroot.us/fullchain.pem. Your cert will expire on 2017-07-16. 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: https://eff.org/donate-le [[email protected]:~]
ステップ3.NginxWebサーバーでLet'sEncryptTLS/SSLを構成します。
まず、Certbotを使用して構成時に指定した仮想ホストファイルを編集し、次の3つのディレクティブを追加します。
listen 443 ssl http2; ssl_certificate /etc/letsencrypt/live/idroot.us/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/idroot.us/privkey.pem;
完全なNginx仮想ホスト構成は次のようになります:
server { listen 80; server_name idroot.us www.idroot.us; rewrite ^(.*) https://idroot.us$1 permanent; } server { access_log off; log_not_found off; error_log logs/idroot.us-error_log warn; server_name idroot.us; root /var/www/idroot.us; index index.php index.html index.htm; listen 443 ssl http2; ssl_certificate /etc/letsencrypt/live/idroot.us/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/idroot.us/privkey.pem; ## Stuff required by certbot location ~ /.well-known { allow all; } ## SSL ssl_session_cache shared:SSL:20m; ssl_session_timeout 10m; ssl_prefer_server_ciphers On; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS; ssl_stapling on; ssl_stapling_verify on; resolver 8.8.8.8 8.8.4.4 valid=300s; resolver_timeout 10s; access_log /var/www/idroot.us/logs/access.log; error_log /var/www/idroot.us/logs/error.log; # php-script handler location ~ \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; fastcgi_read_timeout 150; root /var/www/idroid.us/public_html; fastcgi_param SCRIPT_FILENAME /var/www/idroot.us$fastcgi_script_name; include /etc/nginx/fastcgi_params; } location ~ /\.ht { deny all; } }
ステップ5. Let'sEncryptSSL自動更新を設定します。
cronjobを追加して、毎週更新コマンドを実行します。次のコマンドを実行します:
export VISUAL=nano; crontab -e
次の行を貼り付けます:
01 1 * * 0 /usr/bin/certbot renew >> /var/log/ssl-renew.log 06 1 * * 0 /usr/bin/systemctl nginx reload
保存してcrontabテーブルを終了します。
これにより、毎週日曜日の午前1時に実行される新しいcronジョブが作成され、Nginxウェブサーバーがリロードされて変更が適用されます。出力は次のようになります。 /var/log/ssl-renew.log
にログインしました 必要に応じてさらに分析するためのファイル。
おめでとうございます!Let'sEncryptが正常にインストールされました。CentOS7システムにLet'sEncrypt SSLをインストールするためにこのチュートリアルを使用していただき、ありがとうございます。追加のヘルプや役立つ情報については、Let'sEncryptの公式Webサイトを確認することをお勧めします。 。