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 进行访问保护
- IIS搭建ftp服务器的详细教程 2022-11-15
- 阿里云ECS排查CPU数据分析 2022-10-06
- 教你在docker 中搭建 PHP8 + Apache 环境的过程 2022-10-06
- nginx中封禁ip和允许内网ip访问的实现示例 2022-09-23
- 利用Docker 运行 python 简单程序 2022-10-16
- CentOS_mini下安装docker 之 安装docker CE 2023-09-23
- CentOS7安装GlusterFS集群的全过程 2022-10-10
- KVM虚拟化Linux Bridge环境部署的方法步骤 2023-07-11
- 解决:apache24 安装后闪退和配置端口映射和连接超时设置 2023-09-11
- 【转载】CentOS安装Tomcat 2023-09-24
