LoginSignup
1
2

More than 3 years have passed since last update.

【https化】CentOS7+Nginxで無料SSL証明書Let’s Encrypt(レッツ・エンクリプト)を取得する

Last updated at Posted at 2021-02-26

さくらのVPSで契約したサーバーをhttps化するための作業手順をメモしておきます。

前提条件

  • 独自ドメインの設定が完了していること※

http://your_domain_name.comをブラウザで表示できること
※今回無料SSL証明書を発行するLet's Encrypt(レッツ・エンクリプト)は独自ドメインを設定していないと使えないようです。

実現したいこと

  • サーバーのhttps化

作業環境

  • CentOS7
  • Nginx
  • さくらのVPS

参考サイト

https化の手順

  1. Snapインストール
  2. certbotインストール
  3. ブラウザからhttps化されたサーバーへアクセス

Snapインストール

certbotを使うにはSnapが必要なようなので先にインストールします。

sudo yum install snapd

エラーが出る場合はEPELがインストールされていないので、そちらをインストールします。

sudo yum install epel-release

通信するために必要なソケットを有効化します。

sudo systemctl enable --now snapd.socket

シンボリックリンクを有効化します。

sudo ln -s /var/lib/snapd/snap /snap

これでSnapインストール完了です。

certbotインストール

certbotの前に必要なものをインストールします。

sudo snap install core

アップデートの確認

sudo snap refresh core

certbotインストール。

sudo snap install --classic certbot

コマンドが使えるか確認する。

sudo ln -s /snap/bin/certbot /usr/bin/certbot

https化の設定を行っていきます。

sudo certbot --nginx

メールアドレスを登録します。
SSL証明書の期限が切れそうになったら、メールが届くので実際に使っているメールアドレスが良いです。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): your_mail_address@gmail.com

利用規約を読んだ上で、同意のYを入力、エンター。

Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

メールマガジンへの登録をするかどうか。
自分はNoでしたがYesでも。

Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Account registered.

https化したいドメインを聞かれるので番号を入力してエンター。
複数ドメインがある場合は、スペースorカンマで区切ることでまとめてできると思います。
全てのドメインをhttps化したい場合は何も入力せずにエンター。

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: your_domain_name.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 
Requesting a certificate for your_domain_name.com
Performing the following challenges:
http-01 challenge for your_domain_name.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/default.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/default.conf

完了したらhttps化されたURLへアクセスすることができます。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://your_domain_name.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

無料SSL証明書のファイルが保存されている場所が記されています。
後で使うかもなのでメモっておくと良さそうです。
無料SSL証明書は3ヶ月で有効期限が切れるようですが、自動更新を設定できるようです。
certbotのサイトに載っているのでそこまで設定しても良いと思います。
自分は後でやります。

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/your_domain_name/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/your_domain_name/privkey.pem
   Your certificate will expire on 2021-05-27. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again with the "certonly" option. To non-interactively
   renew *all* of your certificates, run "certbot 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

ブラウザからhttps化されたサーバーへアクセス

https://your_domain_name.com
にブラウザからアクセスしてトップページが開けばhttps化は完了です。

参考サイト

次の目標

無料SSL証明書は3ヶ月ごとに有効期限が切れるようなので、自動更新できるようにします。

1
2
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
2