ConoHa VPSの環境にバーチャルドメインを追加していく際の覚書。
1. DNSの設定
あらかじめ、VPSに向けたいドメインのDNSレコードを設定しておく。
2. Let’s Encrypt
ワイルドカード証明書も検討したが、ムームードメインあたりを使ってると、dns認証を自動で行うためのcertbotのプラグインがなかったりするので、証明書の自動更新ができないので、ちょっと面倒だが、バーチャルドメインを追加するたびに証明書を取っていく方が面倒は少なそうだ。
systemctl stop httpd
certbot certonly -n --standalone --agree-tos -d hogehoge.work -m your-account@hogehoge.work --server https://acme-v02.api.letsencrypt.org/directory
3. httpd
FTPとかで常用するアカウントのホームディレクトリ配下にWebコンテンツ用のディレクトリを作っていく。
cd ~
mkdir www
sudo vi /etc/httpd/conf.d/www.hogehoge.work.conf
<Directory "/home/hogehoge/www">
DirectoryIndex index.html index.php
Require all granted
AllowOverride All
</Directory>
<VirtualHost *:80>
ServerName www.hogehoge.work
DocumentRoot /home/hogehoge/www
CustomLog logs/www.hogehoge.work_access.log combined
ErrorLog logs/www.hogehoge.work_error.log
# 常時SSL化
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>
</VirtualHost>
<VirtualHost *:443>
ServerName www.hogehoge.work
DocumentRoot /home/hogehoge/www
CustomLog logs/www.hogehoge.work_access.log combined
ErrorLog logs/www.hogehoge.work_error.log
SSLCertificateFile /etc/letsencrypt/live/www.hogehoge.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.hogehoge.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/www.hogehoge.com/chain.pem
</VirtualHost>
なお、今回のConoHa VPSの場合、普段つかうSSHユーザーとapacheの実行ユーザーが異なる環境になっており、それが原因かどうかわからないが、Webページを表示するにもイチイチSELinuxに引っ掛かりまくる。
chmodコマンドで、普段使いのSSHユーザーのホームディレクトリに、グループとその他の実行権限を付与した状態で、/home/[SSHユーザー名]/www においたファイルをブラウズしようとしたところ、SELinuxがオンならForbidden、オフなら表示できる、となるので、十中八九SELinuxのコンテキストの問題だろうが…
ちょっと、SELinuxはもっと勉強しないと手に負えないので、無効にして運用するか・・・とりあえず、”permissive”にしておいて、ログには残るようにしておこう。
タグ:
#apache #CentOS Stream #certbot #ConoHa VPS #SELinux