このチュートリアルでは、Let'sEncryptSSLをNginxでUbuntu16.04LTSにインストールする方法を紹介します。知らない人のために、LetsEncryptは無料のオープン認証局(CA)です。 )Webサイトやその他のサービスに無料の証明書を提供します。このサービスは、Electronic Frontier Foundation、Mozilla、Cisco Systems、およびAkamaiによってサポートされています。残念ながら、LetsEncrypt.orgの証明書の有効期間は現在3か月です。つまり、次のことを行う必要があります。今のところ、四半期ごとに証明書を更新してください。
この記事は、少なくともLinuxの基本的な知識があり、シェルの使用方法を知っていること、そして最も重要なこととして、サイトを独自のVPSでホストしていることを前提としています。インストールは非常に簡単で、ルートアカウントで実行されていますが、そうでない場合は、'sudoを追加する必要があります。 ‘ルート権限を取得するコマンドに。 Ubuntu 16.04 LTS(Xenial Xerus)サーバーにNginxでSSLを暗号化するステップバイステップのインストールを紹介します。
前提条件
- 次のオペレーティングシステムのいずれかを実行しているサーバー:Ubuntu 16.04 LTS(XenialXerus)。
- 潜在的な問題を防ぐために、OSの新規インストールを使用することをお勧めします。
- サーバーへのSSHアクセス(またはデスクトップを使用している場合はターミナルを開く)
non-root sudo userまたはroot userへのアクセス 。non-root sudo userとして行動することをお勧めします ただし、ルートとして機能するときに注意しないと、システムに害を及ぼす可能性があるためです。
Ubuntu16.04LTSにNginxでSSLを暗号化してインストール
手順1.まず、次のapt-getを実行して、すべてのシステムパッケージが最新であることを確認します。 ターミナルのコマンド。
sudo apt-get update sudo apt-get upgrade
ステップ2.Ubuntu16.04にLet'sEncryptSSLをインストールします。
最初のステップは、プロセスのほとんどすべてを自動化するソフトウェアクライアントであるcertbotをインストールすることです。
add-apt-repository ppa:certbot/certbot apt-get update apt-get install certbot
Nginxもインストールして実行する必要があります。もちろん、以前に構成したウェブホストに証明書を追加する場合、これはすでにインストールされています:
>apt-get install nginx systemctl start nginx
Ubuntu LinuxにSSLを暗号化するための最初のステップは、Nginxサーバーブロック構成内に単純な構成を追加することです。サーバーブロック構成に次の行を追加します。
location ~ /.well-known {
allow all;
} 保存して終了し、変更を適用します:
### nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Nginxを再起動します:
systemctl restart nginx
Certbotで証明書を取得する:
以下のようにコマンドを実行し、「idroot.us」を実際のドメイン名に置き換え、/ var / www/idroot.usを実際のウェブルートパスに置き換えます。
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サーバーでSSL/TLSを構成します。
まず、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が正常にインストールされました。Ubuntu16.04LTSシステムにLet'sEncrypt SSLをインストールするためにこのチュートリアルを使用していただき、ありがとうございます。追加のヘルプや役立つ情報については、公式のLet'sEncryptを確認することをお勧めします。ウェブサイト。