LoginSignup
136
123

More than 5 years have passed since last update.

Apache2.4で、アクセス制限の記述方法が変更されていた

Posted at

事象

Apache2.2をyumインストールしていた環境から、Apache2.4環境に移行するために、2.4をソースビルドでインストールしました。

その際に、必要な設定とあわせてバーチャルホストも設定。2.2の設定内容を、そのままconf/extra/httpd-vhosts.confに記述しました。

conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
  ServerName sandbox
  ServerAdmin test@example.com
  DocumentRoot /home/sandbox/htdocs/
  ErrorLog /home/sandbox/logs/error_log
  CustomLog /home/sandbox/logs/access_log combined

  <Directory /home/sandbox/htdocs>
    Options FollowSymlinks Includes
    AllowOverride All
    AddType text/html .html
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

Apacheを再起動してブラウザで開いたところ、無情にもForbiddenが・・・。

Forbidden

You don't have permission to access /test.html on this server.

ちなみに、error_logには以下の内容が出力されていました。

AH01630: client denied by server configuration: /home/sandbox/htdocs/index.html

原因

ファイル・ディレクトリのパーミッションを疑う

問題ありませんでした。

Apacheの設定ファイルの記述ミスを疑う

どうやら、2.2から2.4では、アクセス許可設定の方法が変わっているらしい・・・。以下、変更内容。

2.2系
<Directory "/home/sandbox/htdocs">
    Order allow,deny
    Allow from all
</Directory>
2.4系
<Directory "/home/sandbox/htdocs">
    Require all granted
</Directory>

ここを古い記述にしていることで、今回と同様のエラーが出ている人がたくさんいる様子。なるほど、そうだったのか・・・。

ちなみにhttpd.confを見ると、ルートディレクトリのアクセス制限の記述は、以下のとおり。

conf/httpd.conf
<Directory />
    AllowOverride none
    Require all denied
</Directory>

デフォルトではアクセス制限がかかるようになっています。それじゃ、アクセスできませんね・・・。

対応

ということで、httpd-vhosts.confRequire all grantedを追記します。

conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
  ServerName sandbox
  ServerAdmin test@example.com
  DocumentRoot /home/sandbox/htdocs/
  ErrorLog /home/sandbox/logs/error_log
  CustomLog /home/sandbox/logs/access_log combined

  <Directory /home/sandbox/htdocs>
    Options FollowSymlinks Includes
    AllowOverride All
    AddType text/html .html

    # ここを変更
    Require all granted
  </Directory>
</VirtualHost>

Apacheを再起動して、再度ブラウザでアクセス。無事に表示されました。

136
123
3

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
136
123