鈍足ランナーのIT日記

走るのが好きな5流のITエンジニアのブログ。

趣味の範囲は広いけど、どれも中途半端なクソブロガー楽しめるWebアプリを作ってあっと言わせたい。サーバーサイドPerl(Mojolicious)、クライアントサイドVue.js。Arduinoにも触手を伸ばす予定。

HTTPS化にチャレンジ

ググりまくり、letencryptが無料とのことでやってみることにした。
CentOS6+Nginxで設定する

python2.7をインストール

rootユーザでpyenvをインストールする

GitHub - pyenv/pyenv: Simple Python version management

python2.7.8をインストール

pyenv install 2.7.8

nginxを検出できるようにシンボリックリンクを貼る

./path/to/certbot-auto --nginx · Issue #4937 · certbot/certbot · GitHub

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
ln -s /usr/local/nginx/conf/ /etc/nginx

certbot-autoの導入

certbot.eff.org

sudo yum install epel-release

wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto

certbot-autoは/usr/binへ移動した

pyenv shell 2.7.8
pip install virtualenv
certbot-auto --nginx

証明書用のdocument root用のディレクトリを作成する

mkdir /var/www/letsencrypt/

nginxの設定ファイルの編集

        location ~ /\.well-known/acme-challenge/ {
           allow all;
           root /var/www/letsencrypt;
           try_files $uri = 404;
           break;
        }

証明書の取得

certbot-auto certonly --webroot -w /var/www/letsencrypt

nginxのHTTPSの設定

以下のコマンドでをnginxの設定ファイルへ書き加える

certbot-auto install --nginx -d hogehoge.com --cert-path /etc/letsencrypt/live/hogehoge.com/cert.pem --key-path /etc/letsencrypt/live/hogehoge.com/privkey.pem --fullchain-path /etc/letsencrypt/live/hogehoge.com/fullchain.pem 

リダイレクトの設定も必要ならば加える(前は自動で書いてくれていたはずなんですが。・・)

    if ($scheme != "https"){
        return 301 https://$host$request_uri;
    } # managed by Certbot

iptablesの443ポートは開いてますか?

証明書の更新

0 4 1 * * /usr/bin/certbot-auto renew && service nginx reload