apache中关于目录访问权限设置

注意一下apache的版本。

****************************************

apeche2.2

1、想禁止来自某个网站或IP的访问,


Order Allow,Deny

Allow from all
Deny from domain.org #禁止domain.org访问本服务器


2、仅允许某一个网站或IP访问本服务器


Order Allow,Deny
Allow from ip1 #仅允许指定IP来访问服务器


3、允许所有IP访问

Order Allow,Deny
Allow from all #仅允许所有IP来访问服务器


******************************************

请检查你的apache版本,2.2和2.4的权限配置写法是不一样的。

2.2的如下:

Options Indexes FollowSymLinks
AllowOverride All
Allow from all
Order allow,deny

2.4的如下:

 Options Indexes FollowSymlinks
 AllowOverride All
 Require all granted



<Directory "网站目录">
   Options Indexes FollowSymlinks #
   AllowOverride All
   Require all granted
    </Directory>

****************************************

转别人的

Apache 从2.2升级到 Apache2.4.x 后配置文件 httpd.conf 的设置方法有了大变化,以前是将 deny from all 全部改成 Allow from all 实现外网访问,现在是将 Require all denied 以及 Require local 都该为 Require all granted 就可以了。

.htaccess 如果不起作用将 LoadModule rewrite_module modules/mod_rewrite.so 前面的注释(#)去掉就可以了。

下面看一下 Apache2.4 的变化:(官方英文说明

所有的请求都被拒绝

2.2上的配置

Order deny,allow
Deny from all

2.4上的配置

Require all denied

所有请求都是允许的

2.2上的配置

Order allow,deny
Allow from all

2.4上的配置

Require all granted

在域中的所有主机都可以访问example,所有其他外网主机的访问被拒绝

2.2上的配置

Order Deny,Allow
Deny from all
Allow from example.org

2.4上的配置

Require host example.org

要想外网访问将 Require local 该为 Require all granted 。

?
1
2
3
4
5
6
经常会用到的:
Require all denied
Require all granted
Require host xxx.com
Require ip 192.168.1 192.168.2
Require local


Require all denied

Require all granted

Require host xxx.com

Require ip 192.168.1 192.168.2

Require local

举例说明

仅允许IP:192.168.0.1 访问

Require all granted
Require ip 192.168.0.1

仅禁止IP:192.168.0.1访问

Require all granted
Require not ip 192.168.0.1

允许所有访问

Require all granted

拒绝所有访问

Require all denied

默认是 Require local 仅允许本地访问。



猜你喜欢

转载自blog.csdn.net/ddv1999/article/details/78434324
今日推荐