0
2

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 3 years have passed since last update.

apacheでのWordPressをssl化するためのメモ

Posted at

何回もハマったので忘れないうちにメモを残します

環境

$ uname -v
#21~18.04.1-Ubuntu SMP Mon Jul 13 03:31:28 UTC 2020

状況説明

wordpressを構築するまでは、この記事を参照にしました。

最初はcertbotのサイトの手順にしたがって、
snapでcertbotをインストールして証明書を取得しましたが、
apacheの方の自動設定がうまく行かなかったです。

下の方法はaptでcertbotをインストールする方法です。
先頭にsudoをつける、またはrootユーザーで実行してください。

設定ファイルの編集

まず、apacheの設定ファイルを編集して、必要な項目を追加します

$ sudo vim /etc/apache2/sites-available/000-default.conf

11行目あたりに、ServerAdminDocumentRootがあると思います
この2項目は、default-ssl.confファイルにもありますので、
変更するなら、000-default.confdefault-ssl.conf両方変えましょう

  • ServerAdminは自分のメールアドレスを入れるところ
  • DocumentRootはwebページのルートディレクトリの場所を指している
    リンクがドメイン/wordpress/...になって欲しくなければ、
    ここを/var/www/html/wordpressに変えると良いでしょう

この2つの項目の後ろ(前でも良いけど)に、ServerNameServerAliasを追加します
これは、certbotで自動設定を行うときに必要になります

  • ServerName example.com
  • ServerAlias www.example.com

certbotのインストール

次に、certbotをインストールして、apacheのプラグインで、自動設定を行います。

$ sudo apt update
$ sudo apt -y upgrade
$ sudo apt -y install certbot python3-certbot-apache
$ sudo certbot --apache

これで自動設定が始まります。

  • メールアドレスを入力
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel):
  • 規約に同意する必要があるので、aを入力してエンター
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel:
  • シェアされたくないので、nを入力してエンター

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing 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:
  • https化するドメインを選択。ここで1を選択します。
    (空欄で進めてもいいかも)
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: example.com
2: www.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):
  • 問題がなければ、下のようなメッセージが表示されます

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.tk
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/000-default-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/000-default-le-ssl.conf
  • リダイレクトするかどうか聞かれるので、2を選択します

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
  • 成功したら、下のメッセージが表示されます

Congratulations! You have successfully enabled https://example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2020-11-20. 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"
 - Some rewrite rules copied from
   /etc/apache2/sites-enabled/000-default.conf were disabled in the
   vhost for your HTTPS site located at
   /etc/apache2/sites-available/000-default-le-ssl.conf because they
   have the potential to create redirection loops.
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

WordPress側の設定

apacheを再起動して、変更を反映させる前に、WordPressの設定を先に変えましょう
設定画面に行って、WordPress アドレス (URL)サイトアドレス (URL)を変えます

スクリーンショット 2020-08-22 11.18.49.png

保存できたら、systemctl restart apache2で再起動すれば、
https化できたはずだと思います

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?