0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

lets encrypt 導入メモ

Posted at

はじめに

近年セキュリティ上の観点から、googleではhttp通信ではなくhttps通信を推奨しています。httpを利用している場合には警告が表示されるようになり、今後よりいっそう制約が厳しくなっていくものと考えられます。

https化するには様々な手段があり、安全性のレベルにより費用も年間数百円〜数十万円とかなり幅広くなります。

低費用かつ最低限の暗号化を行うという考えの下で複数の方法を試してみましたが,やはりlet encryptの導入が簡単だったので、メモを残します。

環境

  • ubuntu16.04
  • nginx

インストール

lets encryptを使用するにはcertbotが必要です

apt-get  -y install certbot

証明書作成

certbot certonly --webroot -w /var/www/html/ -d xxxx.yyyyyyyyy.zzz
  • certonly : 証明書のみを取得、自動インストールはしない
  • webroot : 証明書ファイルを取得する
  • w : ルートディレクトリを指定。今回はnginxのデフォルトフォルダ。
  • d : 事前にIP設定をしたドメイン名を指定

以下に証明書が作成される

ls /etc/letsencrypt/live/xxxx.yyyyyyyyyy.zzzz/
cert.pem  chain.pem  fullchain.pem  privkey.pem  README
  • サーバ証明書(公開鍵): cert.pem
  • 中間証明書: chain.pem
  • サーバ証明書と中間証明書の結合ファイル:fullchain.pem
  • 秘密鍵: privkey.pem

nginx 設定

server配下にsslを設定

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    ssl  on;
    ssl_certificate /etc/letsencrypt/live/xxxxx.yyyyyyy.zzzz/fullchain.pem ;
    ssl_certificate_key /etc/letsencrypt/live/xxxxx.yyyyyyy.zzzz/privkey.pem;
    ssl_session_timeout 2m;

    root /var/www/html;

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

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
}

なお443portは開けておくこと

firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload

結果

nginxに接続するとhttpsになっていることを確認できる
nginx.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?