LoginSignup
1
1

More than 5 years have passed since last update.

Let's encrypt 環境の運用

Posted at

Let's encrypt による HTTPS サーバの構築/運用めも。

$ nginx -v
nginx version: nginx/1.10.3 (Ubuntu)
$ more /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS"
$ openssl version
OpenSSL 1.0.2g  1 Mar 2016

パッケージのインストール

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-nginx 

参考: https://certbot.eff.org/lets-encrypt/ubuntuxenial-nginx.html

証明書の取得

以下のシェルスクリプトを実行する。

letsencrypt.sh
#!/bin/sh

DOMAIN=www.example.com
EMAIL=foo@example.com
certbot certonly --nginx -m $EMAIL --agree-tos --non-interactive -d $DOMAIN
$ sudo ./letsencrypt.sh

参考:https://qiita.com/tkykmw/items/9b6ba55bb2a6a5d90963

nginx の設定

/etc/nginx/conf.d/https.conf
server {
    listen 443 default ssl;
    ssl on;
    ssl_certificate /etc/letsencrypt/live/(ドメイン名)/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/(ドメイン名)/privkey.pem;
    ssl_dhparam /etc/nginx/dhparam.pem;
    ssl_prefer_server_ciphers on;
    ssl_session_cache  shared:SSL:10m;
    ssl_session_timeout  10m;
    ssl_protocols TLSv1.2;
    ssl_ciphers 'HIGH !aNULL !eNULL !RSA';
    add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains;';
}
$ openssl dhparam 4096 -out dhparam.pem
$ sudo mv dhparam.pem /etc/nginx/
$ sudo chown root:root /etc/nginx/dhparam.pem
$ sudo service nginx restart
  • TLS1.0/1.1 は切ってみた。PCI DSS で非推奨になったので。
  • RSA 鍵交換は無効化
  • HSTS 対応

参考: https://www.saintsouth.net/blog/safety-of-ssl-certificate-setting-improvements-in-web-server-nginx-to-get-rankaplus-from-ssl-server-test

証明書の更新

cron で毎週 certbot を実行する。

/etc/cron.d/letsencrypt
# run at 1:14 am every monday
1 2 * * 1   root    /usr/bin/certbot renew -q --no-self-upgrade --post-hook "service nginx restart"
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1