Conoha Ubuntu16 無料SSL letsencrypt 導入

無料SSLのLetsencryptの導入メモです。ついでにhttp2も設定します。


公式サイト
https://letsencrypt.jp/



手順



1.インストール
sudo apt-get install letsencrypt



2.コマンドを入力
sudo letsencrypt certonly --webroot --webroot-path /var/www/html/ -d example.jp -d www.example.jp

メールアドレスを聞かれるので入力。

3.SSLの起動に必要なファイルがどこにあるのかわからず作成
mkdir /etc/nginx/ssl
cd /etc/nginx/ssl
openssl dhparam 2048 -out dhparam.pem

4.それっぽくSSLの設定をする。


server {
        listen 80 ;
        listen [::]:80 ;
        return 301 https://$host$request_uri;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }
}server {
         listen 443 http2 ssl default_server;
         listen [::]:443 http2 ssl default_server;
         ssl on;

    ssl_certificate /etc/letsencrypt/live/example.jp/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.jp/privkey.pem;
    ssl_session_timeout 10m;
    ssl_session_cache shared:SSL:1m;
    ssl_session_tickets on;

    ssl_dhparam /etc/nginx/ssl/dhparam.pem;
    ssl_ciphers HIGH:!aNULL:!MD5;

    ssl_prefer_server_ciphers on;

        root /var/www/html;
        index index.php ;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

}

5.接続テスト
設定確認して
nginx -t
サービス再起動
systemctl restart nginx


6. 更新を試してみる。
systemctl stop nginx
certbot renew --force-renew
systemctl start nginx

それっぽいログがでたらおめでとう。

7. 自動更新シェルをつくる
中身は↓でよさげ、cronで週一ぐらい?

#!/bin/sh
systemctl stop nginx
certbot renew
systemctl start nginx

このブログの人気の投稿

laragonのphpmyadminでエラーが出た。

メールサーバの移行(自宅→レンタル) 検討

Conoha VPS Centos7へTeamspeak3の導入