Apache Server下,可以对单个目录进行访问控制,如ip过滤,要求用户名密码进行Basic Auth等。下面使用 .htaccess来实现Auth.首先在配置文件 http.conf里,对所要控制的目录,开启Override功能,如果在这里设置为Allo...

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即可。
原文:http://www.cnblogs.com/liseamas/p/4374507.html
本文标题为:使用Apache .htaccess 进行访问保护


基础教程推荐
- apache和nginx结合使用 2023-09-10
- linux下安装apache与php;Apache+PHP+MySQL配置攻略 2023-08-07
- IIS 6 的 PHP 最佳配置方法 2022-09-01
- centos 7 安装及配置zabbix agent 2023-09-24
- Apache Hudi数据布局黑科技降低一半查询时间 2022-10-06
- Apache服务器配置攻略3 2022-09-01
- linux之conda环境安装全过程 2023-07-11
- nginx.conf(centos7 1.14)主配置文件修改 2023-09-23
- 实战Nginx_取代Apache的高性能Web服务器 2023-09-29
- 服务器添加git钩子的步骤 2022-12-12