AWS Lightsailでサーバーを構築-Webサーバー編

〇XAMPPの設定
以下を参考にした。他には古いバージョン用の設定が多くあるので注意

https://bazubu.com/xampp-wordpress-23795.html

XAMPPのダウンロード

https://www.apachefriends.org/jp/download.html

Apacheバージョンの確認
C:\xampp\apache\bin>httpd.exe -v

Server version: Apache/2.4.43 (Win64)
Apache Lounge VC15 Server built: Apr 22 2020 11:11:00

・起動
以下にXAMPP control Panelのショートカットをコピーする
“C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp”

〇サーバー証明書の取得
・mod_md
apacheのmod_mdモジュールでの作成、更新ができるらしいと聞いて試したが失敗
Windowsでは動かないのかもしれない

http://apache-http-server.18135.x6.nabble.com/mod-md-1-1-0-repeating-on-error-td5040498.html

・Windows用ツールをWindowsサーバーにインストール
https://github.com/win-acme/win-acme/releases からwin-acme.v2.1.8.847.x64.trimmed.zip をダウンロードC:\Tooks\win-acmeに解凍。

・証明書を作成
Apacheを立ち上げておく
C:/xampp/apache/conf/certs フォルダーを作成しておく

ACME.exeを起動
最初は–testオプションを付けてステージングサーバーでテストする。
本番サーバーは回数制限があるため、試行できない。

Please choose from the menu: m
How shall we determine the domain(s) to include in the certificate?: 2
Enter comma-separated list of host names, starting with the common name: mydomain.com,www.mydomain.com
  Suggested friendly name '[Manual] mydomain.com', press to accept or type an alternative: <enter>
How would you like prove ownership for the domain(s)?: 1
Path to the root of the site that will handle authentication: C:/xampp/htdocs
  Copy default web.config before validation? (y/n) - no 
What kind of private key should be used for the certificate?: 2 
How would you like to store the certificate?: 2 Path to folder where .pem files are stored: C:/xampp/apache/conf/certs 
Would you like to store it in another way too?: 5 
Which installation step should run first?: 4 
Enter email(s) for notifications about problems and abuse (comma seperated): postmaster@mydomain.com    
 Terms of service: C:\ProgramData\win-acme\acme-v02.api.letsencrypt.org\LE-SA-v1.2-November-15-2017.pdf Open in default application? (y/n)
Authorize identifier www.mydomain.com
Authorizing www.mydomain.com using http-01 validation (FileSystem)
Answer should now be browsable at http://www.mydomain.com/.well-known/acme-challenge/-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Preliminary validation looks good, but the ACME server will be more thorough
Authorization result: valid
Requesting certificate [Manual] mydomain.com
Store with PemFiles…
Exporting .pem files to C:/xampp/apache/conf/certs
Installing with None…
Adding Task Scheduler entry with the following settings
Name win-acme renew (acme-v02.api.letsencrypt.org)
Path C:\Tools\win-acme.v2.1.8.847.x64.trimmed
Command wacs.exe --renew --baseuri "https://acme-v02.api.letsencrypt.org/"
Start at 09:00:00
Time limit 02:00:00
Do you want to specify the user the task will run as? (y/n*) - yes
Enter the username (Domain\username): xxxxxxxx\yyyyyyy
  Enter the user's password: zzzzzzzzz
Adding renewal for [Manual] www.mydomain.com
   Next renewal scheduled at 20xx/xx/xx xx:xx:xx
   Certificate [Manual] mydomain.com created
Running in mode: Interactive, Simple
Target plugin IIS not available: No supported version of IIS detected.

サーバー証明書はfrendry nameごとに作成され、自動更新もその単位で行われるようだ。

タスクスケジューラにwin-acme renew (acme-v02.api.letsencrypt.org)タスクが追加されている。

 ・作成された証明書をhttpd-ssl.confで指定する

SSLCertificateFile "conf/certs/mydomain.com-crt.pem"
SSLCertificateKeyFile "conf/certs/mydomain.com-key.pem"
SSLCertificateChainFile "conf/certs/mydomain.com-chain.pem"

・証明書の確認

apacheを立ち上げて以下のサイトなどで確認する

https://www.digicert.com/help/

・上記ツールでうまくいかないときは、下記のツールを用いて手動で作成する。

 Let’s Encrypt の証明書をブラウザ上で簡単取得   https://qiita.com/tappie/items/76881fdf7996c57a105a

 ここで作られた署名鍵、RSA秘密鍵をwin-acmeに入力することでアカウントを設定できる
 アカウントが設定できればwin-acmeで自動更新タスクをタスクスケジューラに登録できる

〇MercuryMail

C:\xampp\MercuryMail\LOGSに
IMAP4,POP3,SMTPフォルダーを作成
Mercuri.iniファイルの[Protocols]セクションでS,P,C,Iのみ有効にしておく

・メールサーバーの確認
Microsoftリモート接続アナライザー:送信 SMTP メール

https://testconnectivity.microsoft.com/

Scott Kitterman’s SPF Testing Tools:ドメインのSPFレコードが有効かどうかを確認する。

http://www.kitterman.com/spf/validate.html

・ポート25ブロックへの対応

Host : smtp.gmail.com
Server_Port : 465
SMTP_Username: xxxxxx@gmail.com
SMTP_Password: yyyyyyyyyyyyy 2段階認証にして、アプリパスワード(Windows)を生成したもの