LoginSignup
4
3

More than 1 year has passed since last update.

httpd.confを変更してもApacheのドキュメントルートが変更できない方へ

Last updated at Posted at 2022-08-15

さくらのVPSでせっせと本番環境構築していた際、ドキュメントルートを変更しようとして気づいたら2日ほどハマっていたので備忘録です。

環境

・さくらのVPS
・CentOS7
・Apache2.4.6

前提知識

皆さんご存知のとおりApacheのドキュメントルートは

/etc/httpd/conf/httpd.conf

で設定でき、デフォルトでは

/etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html" 

となっています。

この/var/www/htmlディレクトリ内のindex.phpが、外部からサーバーにアクセスした際に、トップページとして表示されます。

問題

今回私はGitHubのリポジトリから「git pull」し、/var/www/html内にソースコードを取得することとしました。

ディレクトリ構成としては、

/var/www/html/リポジトリ名

といった感じです。

そして、/etc/httpd/conf/httpd.conf の

/etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html" 

を、

/etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html/ディレクトリ名"

に変更しました。

「これでサーバーにアクセスしたら、/var/www/html/ディレクトリ名/index.php が表示されるはずや!」
と期待に胸を膨らませましたが、全く表示されず、期待は粉々に打ち砕かれました。

解決

その後2日ほど格闘したところ、あることに気づきました。

「httpでアクセスするとドキュメントルートの変更が反映されている...!」

なぜかhttpsでアクセスするとドキュメントルートが変更されていないのですが、httpだと適切にアクセスできるのです。

そして色々調べた結果、

/etc/httpd/conf ディレクトリ内にある httpd-le-ssl.conf の4行目あたり

/etc/httpd/conf/httpd-le-ssl.conf
DocumentRoot /var/www/html/

/etc/httpd/conf/httpd-le-ssl.conf
DocumentRoot /var/www/html/ディレクトリ名

と変更することで、無事ドキュメントルートを変更することができました。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3