LoginSignup
1
1

More than 5 years have passed since last update.

letsencryptを利用して無料でSSLを実装

Last updated at Posted at 2019-03-23

letsencrypt をインストール

sudo apt-get install letsencrypt

nginxを停止

letsencrypt が一時的に使用するポート(80番)が競合するので、nginxを停止しておきます。

sudo systemctl stop nginx

次に letsencrypt コマンドを利用して証明書を発行します。

それぞれオプションの意味は下記になります。

certonly: 証明書の生成のみ実行。(サーバ設定は行わない)
standalone: WEBサーバとして letsencrypt に内包されるサーバを使用。(nginx や apacheを利用しない)
-d : https化したいドメインを任意に指定してください。
コマンド入力後、メールアドレスの入力を促されるので入力してください。

sudo letsencrypt certonly --standalone -d 〇〇〇〇〇.com

完了後下記のメッセージが表示され、太字下線部分に証明書のパスが確認できます。

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/〇〇〇〇〇〇.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/〇〇〇〇〇〇.com/privkey.pem
   Your cert will expire on 2019-06-21. To obtain a new or tweaked
   version of this certificate in the future, simply run letsencrypt
   again. To non-interactively renew *all* of your certificates, run
   "letsencrypt renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Nginxの設定

上記で確認した 証明書のパスを nginxの設定に反映させます。

\etc\nginx\sites-enabled\default

server {
    listen 80 ;
    listen [::]:80 ;

# ・・・・・・・・

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/〇〇〇〇〇〇.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/〇〇〇〇〇〇.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

Nginxの再起動

この後、nginxを再起動すれば設定は完了です。

sudo systemctl restart nginx

https://〇〇〇〇〇〇.com にアクセスし、動作を確認してみましょう。
エラー画面が表示される場合は /var/log/nginx/error.log などを確認し、表記通りに修正していくと良いでしょう。

参考

letsencryptを利用して無料でSSLを実装 【Ubuntu16.04 + Nginx】
letsencryptをUbuntu16.04 + Nginxで使ってみた

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