首页 > 数据库技术 > 详细

使用Apache .htaccess 进行访问保护

时间:2015-03-28 18:30:47      阅读:144      评论:0      收藏:0      [点我收藏+]

Apache Server下,可以对单个目录进行访问控制,如ip过滤,要求用户名密码进行Basic Auth等。下面使用 .htaccess来实现Auth.

首先在配置文件 http.conf里,对所要控制的目录,开启Override功能,如果在这里设置为AllowOverride none, .htaccess文件将不起作用。

<Directory "/your/site/dir/need/to/control/">
    Options FollowSymLinks Multiviews
    MultiviewsMatch any
    AllowOverride all
    Require all granted
</Directory>

上面的AllowOverride可以选 FileInfo, AuthConfig, Limit, all, none.

配置文件保存后,重启server. 我在mac os x Yosemite下执行

sudo apachectl restart

Apache的配置文件到此完成,现在在对应的site目录下创建.htaccess文件,如上面的/your/site/dir/need/to/control/.htaccess,内容如下

AuthName name
AuthUserFile /your/site/dir/need/to/control/.htpasswd
AuthType Basic
require valid-user

上面的name为用户login时的用户名,AuthUserFile为存放password的文件。下面讲如何生成.htpasswd文件:

在console(mac os x Yosemite)下使用htpasswd命令生成.htpasswd文件

htpasswd -bc /your/site/dir/need/to/control/.htpasswd name password

现在在浏览器访问 http://host/your/.../control/,会弹出对话框,输入name, password即可。

 

使用Apache .htaccess 进行访问保护

原文:http://www.cnblogs.com/liseamas/p/4374507.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!