LoginSignup
39
35

More than 5 years have passed since last update.

ubuntu14.04 + apache2.4.xでforbbidenが出る場合の解決方法

Last updated at Posted at 2014-04-28

はじめに

こんにちはubuntu14.04。
というわけで、ubuntu14.04 LTSがリリースされましたね。
ubuntu14.04でsudo aptitude install apache2をすると、この記事を書いている現在ではapache 2.4.6が入ってきます。
この記事はapache2.4系ではまりやすい事柄に関してまとめたいと思います。
(つまり別にubuntu14.04特有ではないということだけど…)

症状:forbidden

vhostの設定をして、どう考えてもconfはあっているはずなのに、forbiddenが出る。
例えば、

example.com.conf
<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName www.example.com
    DocumentRoot /mnt/hgfs/vm/www/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory "/mnt/hgfs/vm/www/">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

で、sudo service apache2 restartしても、
「あれっ、なんでforbidden?」
ってなる。
エラーログはこんなかんじ

error.log
...
AH01630: client denied by server configuration: /mnt/hgfs/vm/www/index.html

解決策

アクセス許可の設定が2.4系だと結構変わっている。
ubuntu12.04 LTSをずっと使っていて14.04 LTSを使いはじめると結構はまりがちだと思います。
こんなかんじに変更しましょう。

example.com.conf
<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName www.example.com
    DocumentRoot /mnt/hgfs/vm/www/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory "/mnt/hgfs/vm/www/">
        Require all granted
    </Directory>
</VirtualHost>

この他にも、

    #全拒否
        Require all denied

    #IPアドレスxxx.xxx.xxx.xxxのみ許可
        Require ip xxx.xxx.xxx.xxx

    #ローカルIPアドレスのみGETとPOSTを許可
    #それ以外はGETのみ許可
    <RequireAny>(省略可)
        Require all granted
        Require method GET
        <RequireAll>
            <RequireAny>
                Require ip 192.168.
                Require ip 172.16.
                Require ip 10.
            </RequireAny>
            Require GET POST
        </RequireAll>
    </RequireAny>

これに関してはこちらに詳しく載ってます。

39
35
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
39
35