[備忘録]Let's Encrypt でSSL化してからDocumentRootを変更する方法


問題定義

VPSサーバー(conohaのcentos7)をLet's EncryptでSSL化したもののDocumentRootをvar/www/htmlから変更できない。色々な記事を試したみたが、Apacheの仕組み理解度が薄く本質が読めなく難航したので書き記します。

環境

centos7
Apache/2.4.6

解決方法

SSLのポート番号が443になるので、そちらをVirtualHostで設定してあげましょう。

etc/httpd/conf/httpd.conf
Listen 80
-------下記に追加------
<VirtualHost *:443>
  ServerAdmin root@example.com
  ServerName example.com
  DocumentRoot /お好みのDocumentRoot/
  SSLEngine on
  SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
  SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
  <Directory /お好みのDocumentRoot/
    AllowOverride all
    Require all granted
    Options -MultiViews
  </Directory>
</VirtualHost>
----------------------
#
# Dynamic Shared Object (DSO) Support

httpd.confに上記のコードを追加しましょう。