LoginSignup
9
5

More than 3 years have passed since last update.

ApacheのOrder設定allow,deny(サイトのアクセス制限)でどハマった話

Last updated at Posted at 2018-08-01

Apcheの設定でローカルホストからのみ接続を許可したい

設定ファイルに下記のような記述をした場合

httpd.conf
<Directory "D:/Apache Group/Apache2.2/htdocs">
    Order allow,deny
    Allow from 127.0.0.1
    Deny from all
</Directory>

「あー、これでローカルホストからだけ繋がるようになるんだなー」と察するかと思いますが、
違います。

実は上記の設定を行うと

ど こ か ら も 繋 が り ま せ ん

どうするのが正解?

ローカルホストからのみ接続を許可したい場合は
下記のように設定します

httpd.conf
<Directory "D:/Apache Group/Apache2.2/htdocs">
    Order deny,allow
    Allow from 127.0.0.1
    Deny from all
</Directory>

何が変わったかというと
Order allow,deny

Order deny,allow
に変わりました。

このallow,denyの順番が非常に重要で

httpd.conf
<Directory "D:/Apache Group/Apache2.2/htdocs">
    Order allow,deny
    Allow from 127.0.0.1
    Deny from all
</Directory>

の設定の場合は
「ローカルからの接続はだけは許可する→やっぱり全面的に接続を拒否する!」という感じの順番で処理される為、
「全面的に接続を拒否する!」が効いてしまい、
ど こ か ら も 繋 が り ま せ ん
となります。

httpd.conf
<Directory "D:/Apache Group/Apache2.2/htdocs">
    Order deny,allow
    Allow from 127.0.0.1
    Deny from all
</Directory>

の設定の場合は
「全面的に接続を拒否する!→だけどローカルからの接続は許可するよ...」という順番で処理される為、
ローカルからだけ接続が許可されます。

9
5
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
9
5