2016/01/23

EC2でLet's Encrypt + Nginx を試してみる


Let's Encryptという誰でも無料で使えるSSL/TLS証明書発行サービスがPublic Betaを始めました。
https://letsencrypt.org/


前回、AWSのEC2インスタンスでNgnix+PHP7環境を作ったので、この環境にLet's Encryptの証明書を入れてみます。

Gitクライアントを入れて、letsencryptのライブラリを持ってくる。
 
sudo yum install git
git clone https://github.com/letsencrypt/letsencrypt

Nginxを一旦停止する
 
sudo service nginx stop

証明書を発行する
./letsencrypt-auto certonly --standalone -d [ドメイン名] --debug

※Nginxが既に動いていると怒られる。(stopする)
※ドメインの設定が完了してないと怒られる。(nslookup出来るか確認)

メールアドレス、ドメインを設定する。

Nginxの設定

 
    # HTTPS server
    #
    server {
        listen       443;
        server_name  dev.digitra.net;
        root         html;

        ssl                  on;
        #ssl_certificate      cert.pem;
        ssl_certificate      /etc/letsencrypt/live/[ドメイン名]/cert.pem;
        #ssl_certificate_key  cert.key;
        ssl_certificate_key  /etc/letsencrypt/live/[ドメイン名]/privkey.pem;

        ssl_session_timeout  5m;

        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers   on;

        #charset koi8-r;

        location / {
                index index.html index.php;
        }

        # redirect server error pages to the static page /40x.html
        #
        error_page 404 /404.html;
        location = /40x.html {
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
            include        fastcgi_params;
        }
   }

Nginxを起動する

$ sudo service ngnix start

証明書を更新する

Let's Encryptの証明書の有効期限は90日となっている。(推奨は60日)
なので、定期的に証明書を更新する必要がある。

以下の様なスクリプトをcronに仕込んで自動更新するようにする。

#スクリプト
/home/ec2-user/letsencrypt/letsencrypt-auto certonly --webroot -w /var/www/html -d [ドメイン名] --renew-by-default --debug
service httpd restart

#cronの設定
00 05 01 * * /home/ec2-user/letsencrypt_renew.sh





1 件のコメント:

  1. Slotyro Casino - Las Vegas - MapYRO
    춘천 출장샵 › Casino Hotels › › Casino Hotels Slotyro Casino features: Slotyro Slot Machine 나주 출장안마 Games & Mobile 안동 출장샵 App✔️ Real 광양 출장샵 Money Mobile Casino Games✔️ 바카라 사이트 총판 Fast Payouts ⚡ Getaways at the

    返信削除