SSL証明書構成

4409 ワード

参考ブログ:https://www.jianshu.com/p/8f591692d1ed?tdsourcetag=s_pctim_aiomsg https://www.cnblogs.com/ghjbk/p/6744131.html
Let’s Encryptを使用して無料証明書を取得
git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
./letsencrypt-auto --help

Webrootモードで生成された証明書は、443ポートを検証する必要があります.ポートが占有されている場合は失敗し、congratulationsをプロンプトすると成功します.
./letsencrypt-auto certonly --webroot --webroot-path /usr/share/nginx/html -d yourDomain --agree-tos --email [email protected]

エラー:challenge failed for domain xxx.xxx.cn detail:Invalid response fromhttp://xxx.xxx.cn/.well-known/acme-challenge/...解決方法:ドメイン名が有効かどうかを確認し、実行方法を変更します.
./letsencrypt-auto certonly -w       -d xxx.xxx.cn

取得に成功すると、次のようなものが出力されます.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Obtaining a new certificate
Performing the following challenges:
tls-sni-01 challenge for cjli.info
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/yourDomain/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/yourDomain/privkey.pem
   Your cert will expire on 2018-07-30. To obtain a new or tweaked
   version of this certificate in the future, simply run
   letsencrypt-auto again. To non-interactively renew *all* of your
   certificates, run "letsencrypt-auto 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

dhparamの生成
セキュリティをさらに向上させるには、nginxに2048ビットDH parametersを再生成することを推奨します.
openssl dhparam -out /etc/ssl/certs/dhparams.pem 2048

nginx導入ssl証明書
        server{
                listen       443 ssl;
				#ssl on;
                ssl_certificate  youdomain/fullchain.pem;
                ssl_certificate_key  youdomain/privkey.pem;
                server_name xxx.xxx.cn;
                location / {
                    proxy_pass http://xxx:xx;
                }

httpとhttpを同時に傍受するには、ssl on;行を削除し、sslを443の後ろに書きます.そうしないと、listen ssl;と書くだけです.
証明書の更新
Let’s Encryptが発行するサーバ証明書の有効期間は90日しかないため、長期使用が必要な場合は自動継続期間を設定する必要があります.letsencrypt-autoツールを使用して、手動継続コマンドは次のとおりです.
./letsencrypt-auto renew

自動継続期間とは、上記の手動で証明書を取得する操作を自動タイミングで実行し、Linuxにとってcrontabを使用することができます.
echo '@monthly root /path/to/letsencrypt-auto certonly --webroot --webroot-path /usr/share/nginx/html -d yourDomain --agree-tos --email [email protected] >> /var/log/letsencrypt/letsencrypt-auto-update.log' | tee --append /etc/crontab

NginxのSSLモジュールを開く
Nginx SSLモジュールが開いていない場合、Httpsの構成時にエラーnginx:[emerg]the「ssl」parameter requires ngx_http_ssl_module in/usr/local/nginx/conf/nginx.conf:37ソースパッケージに切り替えます.
cd /usr/local/src/nginx-1.11.3

nginxの既存のモジュールの表示
/usr/local/nginx/sbin/nginx -V

configure arguments:後に表示される既存のconfigureパラメータは次のとおりです.
--prefix=/usr/local/nginx --with-http_stub_status_module

では、新しい構成情報はこのように書くべきです.
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

上のコマンドを実行すればいいです.構成が完了したら、コマンドを実行します.
make

ここではmake installを行わないでください.そうしないと、オーバーライドインストールです.
次に、インストール済みのnginxをバックアップします.
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

そしてコンパイルしたばかりのnginxを元のnginxに上書きします(このときnginxは停止状態になります)
cp ./objs/nginx /usr/local/nginx/sbin/

その後nginxを起動しても、コマンドで成功したかどうかを確認できます.
/usr/local/nginx/sbin/nginx -V 

NginxはSSLセキュリティ証明書の再起動を構成してパスワードの入力を避ける
秘密鍵でこのことをすることができます.元のkeyファイルの代わりに復号されたkeyファイルを生成します.
openssl rsa -in server.key -out server.key.unsecure

Nginx SSL性能調整
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;