Apache をインストールして、デフォルトの状態で疎通できたので、まずはSSL化を行っていく。
まずは、Let’s Encrypt(certbot)で取得した証明書ファイルのパスを確認しておく。
sudo ls -al /etc/letsencrypt/live/test.hogehoge.com
README
cert.pem -> ../../archive/test.hogehoge.com/cert1.pem
chain.pem -> ../../archive/test.hogehoge.com/chain1.pem
fullchain.pem -> ../../archive/test.hogehoge.com/fullchain1.pem
privkey.pem -> ../../archive/test.hogehoge.com/privkey1.pem
READMEもふくめて5つほどファイルが作られているが、Apache のSSL化で必要になるのは以下の3つのファイル。
- fullchain.pem
- privkey.pem
- chain.pem
1. ssl.conf の設定
sudo vi /etc/httpd/conf.d/ssl.conf
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt ### 元の記述をコメントアウト
SSLCertificateFile /etc/letsencrypt/live/test.hogehoge.com/fullchain.pem ### この行追加
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key ### 元の記述をコメントアウト
SSLCertificateKeyFile /etc/letsencrypt/live/test.hogehoge.com/privkey.pem ### この行追加
SSLCertificateChainFile /etc/letsencrypt/live/virtual.office-iwakiri.com/chain.pem ### この行追加
SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 ### この行追加
2. welcome.conf の設定
ファイル一覧の表示やエラードキュメントの設定をコメントアウト。SSL化に直接関係はないが、余分な表示をしないための措置。
sudo vi /etc/httpd/conf.d/welcome.conf
<locationmatch "^/+$">
# Options -Indexes
# ErrorDocument 403 /noindex/index.html
</locationmatch>
3. httpd.conf の設定
sudo vi /etc/httpd/conf/httpd.conf
### ドキュメントルートのDirectoryディレクティブ
<directory "/var/www/html/">
Options Indexes FollowSymLinks
↓
Options FollowSymLinks ## 変更
</directory>
### ファイルの末尾に追加
ServerTokens ProductOnly
ServerSignature Off
4. rewrite.conf の作成
httpsへのリダイレクトを設定する。
sudo vi /etc/httpd/conf/rewrite.conf
<ifmodule mod_rewrite.c="">
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</ifmodule>
ここまでやって、https で apache のデフォルトのページが表示できるのが確認できた。
が、PHPを実行しようとすると、全く表示できない。
最初は、PHPのソースがそのまま表示されていたが、どうやらそれは PHP-FPMを入れ忘れてたのが原因のようなので入れなおした。
しかし、今度は503エラーで phpinfo すら表示できない。
さくら公式のスタートアップスクリプトみても、特にPHP-FPM入れてる形跡もないし、PHPの設定も特に行ってないようなんだが…
この辺の情報見る限りでは、特に問題はなさそうなんだが…作業の順番がごちゃごちゃしてると、依存関係で何かと過不足が出てしまうのか…?
それとも、apache のエラーログに出ていた下記のメッセージにヒントがあるのか?
[Tue Nov 24 18:53:05.471872 2020] [mpm_event:notice] [pid 696124:tid 140372414003520] AH00492: caught SIGWINCH, shutting down gracefully
[Tue Nov 24 18:54:16.668395 2020] [suexec:notice] [pid 712:tid 140266279500096] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Nov 24 18:54:18.449150 2020] [lbmethod_heartbeat:notice] [pid 712:tid 140266279500096] AH02282: No slotmem from mod_heartmonitor
[Tue Nov 24 18:54:18.454640 2020] [mpm_event:notice] [pid 712:tid 140266279500096] AH00489: Apache/2.4.37 (centos) OpenSSL/1.1.1c configured -- resuming normal operations
[Tue Nov 24 18:54:18.454663 2020] [core:notice] [pid 712:tid 140266279500096] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
ちょっと調べたら、メモリが足らん時にこのメッセージ、といった情報もあったが…さくらVPSのメモリ512MBプランだとPHPまともに動かんのか??
さらに色々いじってたら、PHP-FPMを入れようとした手順がまずかったのか、こんな状態になってしまった。
rpm -qa | grep php
php-fpm-7.4.12-1.el8.remi.x86_64
php74-1.0-3.el8.remi.x86_64
php-xml-7.4.12-1.el8.remi.x86_64
php74-php-json-7.4.12-1.el8.remi.x86_64
php74-php-pecl-mysql-1.0.0-0.23.20190415.d7643af.el8.remi.x86_64
php-common-7.4.12-1.el8.remi.x86_64
php-mbstring-7.4.12-1.el8.remi.x86_64
php74-php-common-7.4.12-1.el8.remi.x86_64
php74-php-mysqlnd-7.4.12-1.el8.remi.x86_64
php-json-7.4.12-1.el8.remi.x86_64
php-cli-7.4.12-1.el8.remi.x86_64
php74-php-cli-7.4.12-1.el8.remi.x86_64
oniguruma5php-6.9.6-1.el8.remi.x86_64
php74-php-imap-7.4.12-1.el8.remi.x86_64
php74-php-fpm-7.4.12-1.el8.remi.x86_64
php74-runtime-1.0-3.el8.remi.x86_64
php74-php-mbstring-7.4.12-1.el8.remi.x86_64
php74-php-pdo-7.4.12-1.el8.remi.x86_64
・・・もっかいやり直すか。今度はパッケージのインストールだけでもスクリプト化してみるか。
このあたりの情報整理して、再チャレンジだ。