-->

apachectl -M
sudo apt install mod_ssl
cd /etc/apache2/mods-avaliable
sudo vi proxy.load

cd /etc/apache2/sites-available
sudo vi default-ssl.conf
<VirtualHost *:443>
ServerAdmin 「管理者のメールアドレス」
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#確認したLoadModuleコマンドを打ち込む
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so
#https通信設定
<VirtualHost *:443>
DocumentRoot /var/www/engineer.host
ServerName unity-engineer.top
ErrorLog /var/log/apache2/engineer.host.error.log
CustomLog /var/log/apache2/engineer.host.access.log combined
#SSLを有効化
SSLEngine on
#最新のプロトコルのみ許可
SSLProtocol TLSv1.2 TLSv1.3
#安全な暗号化アルゴリズムだけを網羅して許可
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-G CM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
#ブラウザ側に暗号化アルゴリズムを選択させる(接続スピード強化)
SSLHonorCipherOrder off
#セッションごとに使い捨ての鍵を使う(前方秘匿性強化)
SSLSessionTickets off
SSLCertificateFile 「unity-engineer.top の cert.pem(SSLサーバー証明書)の path」
SSLCertificateKeyFile 「unity-engineer.top の privkey.pem(秘密鍵)の path」
SSLCertificateChainFile 「unity-engineer.top の chain.pem(中間証明書)の path」
ProxyRequests Off
SSLProxyEngine On
# errprsページ以外のアクセスは、リバースプロキシを使ってTomcatページに移動させる
ProxyPass /errors !
ProxyPass / https://unity-engineer.top:「Tomcatのhttpsポート設定」/「Tomcatのwebapps下サイトディレクトリ」
ProxyPassReverse / https://unity-engineer.top:「Tomcatのhttpsポート設定」/「Tomcatのwebapps下サイトディレクトリ」
# URL末尾が/homeであった場合、サイトトップページに移動させる
RewriteEngine On
RewriteRule ^/home / [R=301,L]
# サーバーからerrorが返ってきたときは、それぞれのエラーに応じてDocumentRoot下のページに移動させる
ProxyErrorOverride On
ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 408 /errors/408.html
ErrorDocument 500 /errors/500.html
ErrorDocument 502 /errors/502.html
ErrorDocument 503 /errors/503.html
ErrorDocument 504 /errors/504.html
</VirtualHost>
#http通信設定、httpsに受け流す
#ただしwell-knownからのアクセス(Let's Enctyptからのアクセス)はhttpsに移動させずhttpのDocumentRootに移動させる
<VirtualHost *:80>
DocumentRoot /var/www/engineer.host
ServerName unity-engineer.top
ErrorLog /var/log/apache2/engineer.host.error.log
CustomLog /var/log/apache2/engineer.host.access.log combined
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
</VirtualHost>
#unity-engineer.topのhttp接続ならこっちの遷移
<VirtualHost *:80>
DocumentRoot /var/www/engineer.host
ServerName unity-engineer.top
ErrorLog /var/log/apache2/engineer.host.error.log
CustomLog /var/log/apache2/engineer.host.access.log combined
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
</VirtualHost>
#english-everyday.topのhttp接続ならこっちの遷移
<VirtualHost *:80>
DocumentRoot /var/www/english.host
ServerName english-everyday.top
ErrorLog /var/log/apache2/english.host.error.log
CustomLog /var/log/apache2/english.host.access.log combined
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
</VirtualHost>
a2ensite default-ssl
a2enmod ssl
sudo service apache2 restart