云计算学习路线教程大纲课堂笔记:Apache访问控制:php
========================================================html
1、目录访问控制的类型web
设置目录特性ide
基于主机学习
2、基于主机的访问控制ui
准备环境云计算
[root@aliyun ~]# rm -rf /var/www/edusoho/web/download/*htm
[root@aliyun ~]# echo "download....." > /var/www/edusoho/web/download/1.html教程
仅用于http 2.4+ip
案例1:容许全部主机访问
<Directory "/var/www/edusoho/web/download">
AllowOverride None
Require all granted
</Directory>
AllowOverride All 容许子目中的 .htaccess 中的设置覆盖当前设置
AllowOverride None 不容许子目中的 .htaccess 中的设置覆盖当前设置
案例2:只容许网段192.168.5.0/2四、192.168.10.0/24访问
<Directory "/var/www/edusoho/web/download">
AllowOverride None
Require ip 202.106.0.0/24
Require ip 114.248.160.203
</Directory>
案例3:只拒绝某些主机访问
<Directory "/var/www/edusoho/web/download">
AllowOverride None
<RequireAll>
Require not ip 114.248.160.203
Require all granted
</RequireAll>
</Directory>
3、基于用户的访问:访问时须要用户名和密码
==使用无格式文本文件
[root@tianyun ~]# htpasswd -cm /etc/httpd/conf/webpasswd user1
New password: 输入密码
Re-type new password: 再输入密码
Adding password for user user1
-c 建立
-m MD5
[root@tianyun ~]# cat /etc/httpd/conf/webpasswd
user1:$apr1$tkLV4/..$BL2nd2Wbx4I5ZAf5uv8ZS.
[root@tianyun ~]# htpasswd -m /etc/httpd/conf/webpasswd user2
<Directory "/var/www/edusoho/web/download">
AllowOverride None
Require all granted
AuthType Basic
AuthName "welcome to tianyun.me..."
AuthUserFile /etc/httpd/webpasswd
Require valid-user
</Directory>
4、针对文件的访问控制
不容许在/var/www/edusoho/web/upload目录中执行.php文件
<Directory /webroot/baidu/upload>
AllowOverride None
Require all granted
<Files ~ ".php$" >
Order allow,deny
Deny from all
</Files>
</Directory>