Let’s Encryptの証明書をnginxに設定してhttps化した

2017年3月10日HTTP SERVERCentOS7, Let’s Encrypt, Nginx, SSL, systemconfigHTTP SERVER, Let’s Encrypt, Nginx, SSL, systemconfig

とりあえずやってみる

Let’s Encryptのインストール

git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
./letsencrypt-auto --help
Bootstrapping dependencies for RedHat-based OSes...
yum is /bin/yum
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
(yumで必要なパッケージがインストールされる)
(途中省略)
Creating virtual environment...
Installing Python packages...
Installation succeeded.



そして証明書を取得してみる。

./letsencrypt-auto certonly --webroot -w /var/home/site/blog.rgm89s.com -d blog.rgm89s.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel):****@gmail.com

-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree
in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A

-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for blog.rgm89s.com
Using the webroot path /var/home/site/blog.rgm89s.com for all unmatched domains.
Waiting for verification...
Cleaning up challenges
Generating key (2048 bits): /etc/letsencrypt/keys/0000_key-certbot.pem
Creating CSR: /etc/letsencrypt/csr/0000_csr-certbot.pem

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/blog.rgm89s.com/fullchain.pem. Your cert will
   expire on 2017-06-08. 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"
 - 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:                    https://eff.org/donate-le



DH鍵交換に使用するパラメータファイルを作成する。

mkdir /var/home/ap/nginx/ssl
openssl dhparam 2048 -out /var/home/ap/nginx/ssl/dhparam.pem
chown -R nginx:nginx /var/home/ap/nginx/ssl



nginxにSSLの設定を追加する。

server {
  ssl_certificate /etc/letsencrypt/live/blog.rgm89s.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/blog.rgm89s.com/privkey.pem;
  ssl_trusted_certificate /etc/letsencrypt/live/blog.rgm89s.com/chain.pem;
  ssl_session_timeout 1d;
  ssl_session_cache shared:SSL:50m;
  ssl_session_tickets on;
  ssl_dhparam /var/home/ap/nginx/ssl/dhparam.pem;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
  ssl_prefer_server_ciphers on;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  listen 443 ssl
  server_name blog.rgm89s.com;
  ..
}



FirewallにHTTPSサービスを追加する。

firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

証明書の自動更新設定

view /usr/lib/systemd/system/certbot.service

[Unit]
Description=Let's Encrypt renewal

[Service]
Type=oneshot
ExecStart=/var/home/lib/letsencrypt/certbot-auto renew --pre-hook "/usr/bin/systemctl stop nginx.service" --post-hook "/usr/bin/systemctl start nginx.service" --quiet --agree-tos
view /usr/lib/systemd/system/certbot.timer

[Unit]
Description=Daily renewal of Let's Encrypt's certificates

[Timer]
OnCalendar=daily
RandomizedDelaySec=1day
Persistent=true

[Install]
WantedBy=timers.target
systemctl enable certbot.timer
systemctl start certbot.timer



ここまで読んで頂きありがとうございます。
現在、ランキング参加中です。良ければランキングボタンをクリック願います。
↓↓↓↓↓↓↓↓

オープンソースランキング

にほんブログ村 IT技術ブログへ
にほんブログ村

にほんブログ村 IT技術ブログ オープンソースへ
にほんブログ村